mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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.
This commit is contained in:
@ -277,7 +277,7 @@ public:
|
||||
void operator|=(const HashSet<Key, Hash>& rhs);
|
||||
|
||||
//- Only retain entries found in both HashSets
|
||||
void operator&=(const HashSet<Key, Hash>& rhs);
|
||||
inline void operator&=(const HashSet<Key, Hash>& rhs);
|
||||
|
||||
//- Only retain unique entries (xor)
|
||||
void operator^=(const HashSet<Key, Hash>& rhs);
|
||||
@ -289,7 +289,7 @@ public:
|
||||
}
|
||||
|
||||
//- Remove entries listed in the given HashSet from this HashSet
|
||||
void operator-=(const HashSet<Key, Hash>& rhs);
|
||||
inline void operator-=(const HashSet<Key, Hash>& rhs);
|
||||
|
||||
|
||||
// IOstream Operator
|
||||
|
||||
Reference in New Issue
Block a user