1. 12 May, 2017 1 commit
  2. 11 May, 2017 1 commit
    • Mark Olesen's avatar
      ENH: added HashTable 'lookup' and 'retain' methods · f73b5b62
      Mark Olesen authored
      - 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.
      f73b5b62
  3. 10 May, 2017 2 commits
  4. 08 May, 2017 4 commits
  5. 07 May, 2017 2 commits
  6. 05 May, 2017 3 commits
  7. 04 May, 2017 11 commits
  8. 02 May, 2017 4 commits
  9. 01 May, 2017 7 commits
    • Mark Olesen's avatar
      ENH: HashSet iterators operator* now return Key. · f8c58bdd
      Mark Olesen authored
      - much more useful than returning nil. Can now use with a for range:
      
          for (auto i : myLabelHashSet)
          {
              ...
          }
      f8c58bdd
    • Mark Olesen's avatar
      ENH: add HashTable::writeKeys and HashSet::writeList · 8f75bfbe
      Mark Olesen authored
      - can use the hash-set writeList in combination with FlatOutput:
      
        Eg, flatOutput(myHashSet);
      8f75bfbe
    • Mark Olesen's avatar
      ENH: improve overall consistency of the HashTable and its iterators · c0a50dc6
      Mark Olesen authored
      - previously had a mismash of const/non-const attributes on iterators
        that were confused with the attributes of the object being accessed.
      
      - use the iterator keys() and object() methods consistently for all
        internal access of the HashTable iterators. This makes the intention
        clearer, the code easier to maintain, and protects against any
        possible changes in the definition of the operators.
      
      - 'operator*': The standard form expected by STL libraries.
        However, for the std::map, this dereferences to a <key,value> pair,
        whereas OpenFOAM dereferences simply to <value>.
      
      - 'operator()': OpenFOAM treats this like the 'operator*'
      
      - adjusted the values of end() and cend() to reinterpret from nullObject
        instead of returning a static iteratorEnd() object.
        This means that C++ templates can now correctly deduce and match
        the return types from begin() and end() consistently.
        So that range-based now works.
      
        Eg,
            HashTable<label> table1 = ...;
            for (auto i : table1)
            {
                Info<< i << endl;
            }
      
        Since the 'operator*' returns hash table values, this prints all the
        values in the table.
      c0a50dc6
    • Mark Olesen's avatar
      ENH: ensure nullObject is large enough for reinterpret · 0298c02b
      Mark Olesen authored
      - previously occupied 1 byte. Now occupies enough to hold a pointer,
        which helps if using reinterpret_cast to something that has some
        member content.
      0298c02b
    • Mark Olesen's avatar
      BUG: comparison to static end() for hashtable lookup. · 7cceda62
      Mark Olesen authored
      - just use the iterator method found() as an alternative and
        convenient way to avoid the issue with less typing.
      7cceda62
    • Mark Olesen's avatar
      BUG: comparison with incorrect construction tables · dc57c016
      Mark Olesen authored
      - previously hidden when hashtable used a static method and a
        different class for end()
      dc57c016
    • Mark Olesen's avatar
      ENH: support UList[labelRange] and SubList construction with labelRange · 805b76d4
      Mark Olesen authored
      This uses a concept similar to what std::valarray and std::slice do.
      A labelRange provides a convenient container for holding start/size
      and lends itself to addressing 'sliced' views of lists.
      For safety, the operations and constructors restricts the given input range
      to a valid addressible region of the underlying list, while the labelRange
      itself precludes negative sizes.
      
      The SubList version is useful for patches or other things that have a
      SubList as its parameter. Otherwise the UList [] operator will be the
      more natural solution. The slices can be done with a labelRange, or
      a {start,size} pair.
      
      Examples,
           labelList list1 = identity(20);
      
           list1[labelRange(18,10)]  = -1;
           list1[{-20,25}] = -2;
           list1[{1000,5}] = -3;
      
           const labelList list2 = identity(20);
           list2[{5,10}] = -3;  // ERROR: cannot assign to const!
      805b76d4
  10. 30 Apr, 2017 3 commits
  11. 29 Apr, 2017 2 commits
    • Mark Olesen's avatar
      ENH: add some standard templates and macros into stdFoam.H · c65e2e58
      Mark Olesen authored
      - some functionality similar to what the standary library <iterator>
        provides.
      
        * stdFoam::begin() and stdFoam::end() do type deduction,
          which means that many cases it is possible to manage these types
          of changes.
      
          For example, when managing a number of indices:
             Map<labelHashSet> lookup;
      
          1) Longhand:
      
              for
              (
                  Map<labelHashSet>::const_iterator iter = lookup.begin();
                  iter != lookup.end();
                  ++iter
              )
              { .... }
      
          1b) The same, but wrapped via a macro:
      
              forAllConstIter(Map<labelHashSet>, lookup, iter)
              { .... }
      
          2) Using stdFoam begin/end templates directly
      
              for
              (
                  auto iter = stdFoam::begin(lookup);
                  iter != stdFoam::end(lookup);
                  ++iter
              )
              { .... }
      
          2b) The same, but wrapped via a macro:
      
              forAllConstIters(lookup, iter)
              { .... }
      
      Note that in many cases it is possible to simply use a range-based for.
      Eg,
           labelList myList;
      
           for (auto val : myList)
           { ... }
      
           for (const auto& val : myList)
           { ... }
      
      These however will not work with any of the OpenFOAM hash-tables,
      since the standard C++ concept of an iterator would return a key,value
      pair when deferencing the *iter.
      
      The deduction methods also exhibits some slightly odd behaviour with
      some PtrLists (needs some more investigation).
      c65e2e58
    • Mark Olesen's avatar
      ENH: improve HashSet construction and assignment · 6a5ea9a2
      Mark Olesen authored
      - 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.
      6a5ea9a2