Commit Graph

39 Commits

Author SHA1 Message Date
Mark Olesen
b33b26ad34 STYLE: replace zero::null usage with zero
- the null output adapter was previously used for the HashTables API
  when HashSet actually stored key/value. Now that the node only
  contains the key, having suppressed output is redundant, as is the
  zero::null class (reduces clutter)

STYLE: replace one::minus dispatch in extendedEdgeMesh

GIT: remove Foam::nil typedef (deprecated since May-2017)
2023-02-27 15:41:25 +01:00
Mark Olesen
375a4792f9 ENH: HashSet, HashTable, HashPtrTable merge() method
- name and functionality similar to std::unordered_map (C++17).
  Formalizes what had been previously been implemented in IOobjectList
  but now manages without pointer deletion/creation.
2023-02-13 21:22:20 +01:00
Mark Olesen
3151dacccc ENH: include <algorithm> in stdFoam.H
- was already included in many places (via UList.C templates), but now
  formalise by placing in stdFoam.H
2022-12-01 15:52:48 +00:00
Mark Olesen
95cd8ee75c ENH: improve hashing overloads of string-types and HashTable/HashSet
- additional dummy template parameter to assist with supporting
  derived classes. Currently just used for string types, but can be
  extended.

- provide hash specialization for various integer types.
  Removes the need for any forwarding.

- change default hasher for HashSet/HashTable from 'string::hash'
  to `Hash<Key>`. This avoids questionable hashing calls and/or
  avoids compiler resolution problems.

  For example,
  HashSet<label>::hasher and labelHashSet::hasher now both properly
  map to Hash<label> whereas previously HashSet<label> would have
  persistently mapped to string::hash, which was incorrect.

- standardize internal hashing functors.

  Functor name is 'hasher', as per STL set/map and the OpenFOAM
  HashSet/HashTable definitions.

  Older code had a local templated name, which added unnecessary
  clutter and the template parameter was always defaulted.
  For example,

      Old:  `FixedList<label, 3>::Hash<>()`
      New:  `FixedList<label, 3>::hasher()`
      Unchanged:  `labelHashSet::hasher()`

  Existing `Hash<>` functor namings are still supported,
  but deprecated.

- define hasher and Hash specialization for bitSet and PackedList

- add symmetric hasher for 'face'.
  Starts with lowest vertex value and walks in the direction
  of the next lowest value. This ensures that the hash code is
  independent of face orientation and face rotation.

NB:
  - some of keys for multiphase handling (eg, phasePairKey)
    still use yet another function naming: `hash` and `symmHash`.
    This will be targeted for alignment in the future.
2021-04-19 16:33:42 +00:00
Andrew Heather
fdf8d10ab4 Merge commit 'e9219558d7' into develop-v1906 2019-12-05 11:47:19 +00:00
OpenFOAM bot
e9219558d7 GIT: Header file updates 2019-10-31 14:48:44 +00:00
Mark Olesen
bbc2d4a8b0 ENH: HashTable and HashSet improvements
- unfriend HashSet, HashTable IO operators

- global min(), max(), minMax() functions taking a labelHashSet and an
  optional limit. For example,

      labelHashSet set = ...;

      Info<< "min is " << min(set) << nl;
      Info<< "max (non-negative) " << max(set, 0) << nl;

- make HashTable iterator '->' dereferencing more consistent by also
  supporting non-pointer types as well.

- read HashTable values in-situ to avoid copying
2019-07-12 18:00:00 +02:00
Mark Olesen
e9323ecbbb STYLE: use finiteVolume in Make/options placeholder 2019-02-24 17:32:13 +01:00
OpenFOAM bot
154029ddd0 BOT: Cleaned up header files 2019-02-06 12:28:23 +00:00
Mark Olesen
3560884abe ENH: allow direct testing of HashTable iterator as a bool
- can be used as a more natural test on the iterator.
  For example, with

     HashTable<..> table;
     auto iter = table.find(...);

  Following are now all equivalent:

    1.  if (iter != table.end()) ...
    2.  if (iter.found()) ...
    3.  if (iter) ...
2018-12-20 18:03:16 +01:00
Mark Olesen
6b6b36afd3 STYLE: revert bitSet/HashSet setMany() to set() method (issue #837)
- improves backward compatibility and more naming consistency.
  Retain setMany(iter1, iter2) to avoid ambiguity with the
  PackedList::set(index, value) method.
2018-05-29 17:38:02 +02:00
Mark Olesen
d17bc72585 ENH: consistency of HashSet setMany(), insertMany() with packed-list version
- this also provides a better separation of the intent
  (ie, inserting a single value, or inserting multiply values)
2018-03-14 21:08:29 +01:00
Mark Olesen
bcabe827f6 ENH: dedicated HashSetOps, HashTableOps namespaces
- relocated HashSetPlusEqOp and HashTablePlusEqOp to
  HashSetOps::plusEqOp and HashTableOps::plusEqOp, respectively

- additional functions for converting between a labelHashSet
  and a PackedBoolList or List<bool>:

  From lists selections to labelHashSet indices:

      HashSetOps::used(const PackedBoolList&);
      HashSetOps::used(const UList<bool>&);

  From labelHashSet to list forms:

      PackedBoolList bitset(const labelHashSet&);
      List<bool> bools(const labelHashSet&);
2018-03-06 11:41:34 +01:00
Mark Olesen
09a6e94073 BUG: incorrect HashTable / HashSet instances
- Eg instead of using labelHashSet, used HashSet<label> which uses
  the string::hash for hashing. Other places inadvertently using the
  string::hash instead of Hash<label> for hashing.

STYLE: use Map<..> instead of HashTable<.., label, Hash<label>>

- reduces clutter
2018-02-09 09:30:02 +01:00
Mark Olesen
930d6dcaf2 ENH: dummy I/O for nullObject, additional null subclass for zero/one
- the zero::null and one::null sub-classes add an additional null
  output adapter.

  The function of the nil class (special-purpose class only used for
  HashSet) is now taken by zero::null.
2017-10-31 10:54:17 +01:00
Mark Olesen
049617d037 ENH: update List and DynamicList methods (issue #595)
- improve functional compatibility with DynList (remove methods)
  * eg, remove an element from any position in a DynamicList
  * reduce the number of template parameters
  * remove/subset regions of DynamicList

- propagate Swap template specializations for lists, hashtables

- move construct/assignment to various containers.

- add find/found methods for FixedList and UList for a more succinct
  (and clearer?) usage than the equivalent global findIndex() function.

- simplify List_FOR_ALL loops
2017-09-20 17:20:54 +02:00
Mark Olesen
f73b5b629f ENH: added HashTable 'lookup' and 'retain' methods
- lookup(): with a default value (const access)
  For example,
      Map<label> something;
      value = something.lookup(key, -1);

    being equivalent to the following:

      Map<label> something;
      value = -1;  // bad value
      if (something.found(key))
      {
          value = something[key];
      }

    except that lookup also makes it convenient to handle const references.
    Eg,

      const labelList& ids = someHash.lookup(key, labelList());

- For consistency, provide a two parameter HashTable '()' operator.
  The lookup() method is, however, normally preferable when
  const-only access is to be ensured.

- retain(): the counterpart to erase(), it only retains entries
  corresponding to the listed keys.

  For example,
      HashTable<someType> largeCache;
      wordHashSet preserve = ...;

      largeCache.retain(preserve);

    being roughly equivalent to the following two-stage process,
    but with reduced overhead and typing, and fewer potential mistakes.

      HashTable<someType> largeCache;
      wordHashSet preserve = ...;

      {
          wordHashSet cull(largeCache.toc()); // all keys
          cull.erase(preserve);               // except those to preserve
          largeCache.erase(cull);             //
      }

  The HashSet &= operator and retain() are functionally equivalent,
  but retain() also works with dissimilar value types.
2017-05-11 12:25:35 +02:00
Mark Olesen
03d180724b ENH: improve HashTable iterator access and management
- provide key_iterator/const_key_iterator for all hashes,
  reuse directly for HashSet as iterator/const_iterator, respectively.

- additional keys() method for HashTable that returns a wrapped to
  a pair of begin/end const_iterators with additional size/empty
  information that allows these to be used directly by anything else
  expecting things with begin/end/size. Unfortunately does not yet
  work with std::distance().

  Example,
     for (auto& k : labelHashTable.keys())
     {
        ...
     }
2017-05-04 10:17:18 +02:00
Mark Olesen
f8c58bdd5c ENH: HashSet iterators operator* now return Key.
- much more useful than returning nil. Can now use with a for range:

    for (auto i : myLabelHashSet)
    {
        ...
    }
2017-05-02 01:58:38 +02:00
Mark Olesen
8f75bfbed5 ENH: add HashTable::writeKeys and HashSet::writeList
- can use the hash-set writeList in combination with FlatOutput:

  Eg, flatOutput(myHashSet);
2017-05-02 00:51:04 +02:00
Mark Olesen
6a5ea9a2bf ENH: improve HashSet construction and assignment
- make construct from UList explicit and provide corresponding
  assignment operator.

- add construct,insert,set,assignment from FixedList.
  This is convenient when dealing with things like edges or triFaces.
2017-04-29 15:19:47 +02:00
Mark Olesen
ded105c539 STYLE: HashTable documentation
- explicitly mention the value-initialized status for the operator().
  This means that the following code will properly use an initialized
  zero.

      HashTable<label> regionCount;

      if (...)
         regionCount("region1")++;

      ... and also this;

      if (regionCount("something") > 0)
      {
          ...
      }

  Note that the OpenFOAM HashTable uses operator[] to provide read and
  write access to *existing* entries and will provoke a FatalError if
  the entry does not exist.

  The operator() provides write access to *existing* entries or will
  create the new entry as required.
  The STL hashes use operator[] for this purpose.
2017-04-29 12:27:11 +02:00
Mark Olesen
934764d700 ENH: optionally eliminate duplicates on hashedWordList construction (issue #375)
- makes it easier to use as a wordHashSet replacement for situations
  where we want to avoid duplicates but retain the input order.

- support construction from HashTable, which means it works like the
  HashTable::sortedToc but with its own hashing for these keys.

- expose rehash() method for the user. There is normally no need for
  using it directly, but also no reason to lock it away as private.
2017-01-10 12:42:40 +01:00
Mark Olesen
1967fd3dad ENH: Support more C++11 initializer lists (issue #261)
DynamicList
-----------
  - construction, assignment and append

HashSet
-------
  - construction, insert, set.
  - assignment will use the implicit List constructor

hashedWordList
--------------
  - construction, assignment
  - additional sort() and uniq() methods.
  - Readonly access to HashTable information via lookup() method.
  - NB: could avoid 'const char**' constructors in the future
2016-10-18 20:08:37 +02:00
Henry
c2dd153a14 Copyright transfered to the OpenFOAM Foundation 2011-08-14 12:17:30 +01:00
andy
eaef8d482b STYLE: Updated 1991 start copyright year to 2004 2011-01-14 16:08:00 +00:00
andy
099cc39e2e Revert "STYLE: 2011 copyright date."
This reverts commit b18f6cc1ce.
2011-01-05 18:24:29 +00:00
graham
b18f6cc1ce STYLE: 2011 copyright date. 2011-01-05 11:14:26 +00:00
Mark Olesen
499d48cfdb STYLE: uniform 'Test-' prefix for all applications/test
- easier to clean, avoid confusion with 'real' applications, etc.
2010-11-23 16:26:04 +01:00
graham
012494fdb5 STYLE: Fixing code style requirements for all apps.
Exception: applyWallFunctionBoundaryConditions.C cannot split #include
directives.
2010-07-27 15:27:05 +01:00
Mark Olesen
d29c438657 STYLE: use url for FSF license instead of postal address, switch to GPL v3 2010-03-29 14:07:56 +02:00
Mark Olesen
a4f4a904f4 HashSet enhancement
- allow insert() and set() from a UList of Key
  This complements the existing erase(const UList<Key>&) method
2009-12-01 18:26:18 +01:00
Mark Olesen
c6e9b323f5 added HashSet::operator[]() const
- can use the same syntax for boolList, PackedBoolList and labelHashSet
    if (myHashedSet[x]) ...
    if (myBoolList[x]) ...
    if (myPackedList[x]) ...
2009-01-27 21:55:03 +01:00
Mark Olesen
f0341171ff renamed 'empty' class to 'nil', added missing empty() member to some containers 2009-01-09 13:10:10 +01:00
Mark Olesen
28b200bcd9 update copyrights for 2009 2008-12-31 19:01:56 +01:00
Mark Olesen
110e9989b9 further HashSet improvements
- added global operator|, operator& and operator^
 - can construct from table of contents of another HashTable
2008-11-19 12:37:37 +01:00
Mark Olesen
1c9102dada HashSet gets additional operators
- operator+=  : add in the listed keys
 - operator-=  : remove the listed keys
 - operator&=  : intersection of keys
 - added xfer constructor (just in case)
 - moved labelHashSet typedef to HashSet.H, for consistency with the
   wordHashSet typedef being there and since it is used so often
2008-11-18 23:11:09 +01:00
Mark Olesen
02cabc3cf2 updated Copyright (C) \d+-2008 OpenCFD Ltd. 2008-06-25 15:01:46 +02:00
OpenFOAM-admin
3170c7c0c9 Creation of OpenFOAM-dev repository 15/04/2008 2008-04-15 18:56:58 +01:00