HashSet and PackedList get an unset() method

- provides a convenient (and lazy) means of removing entries
This commit is contained in:
Mark Olesen
2009-12-08 10:01:48 +01:00
parent 16c715ceec
commit d2d39c32be
4 changed files with 32 additions and 1 deletions

View File

@ -136,6 +136,12 @@ public:
return insert(lst);
}
//- Unset the specified key - same as erase
bool unset(const Key& key)
{
return HashTable<nil, Key, Hash>::erase(key);
}
// Member Operators

View File

@ -201,6 +201,10 @@ public:
// Default value set is the max_value.
inline bool set(const label, const unsigned int val = ~0u);
//- Unset the entry at index I. Return true if value changed.
// Never auto-vivify entries.
inline bool unset(const label);
//- Return the underlying packed storage
inline List<unsigned int>& storage();
@ -240,6 +244,8 @@ public:
//- Reserve allocation space for at least this size.
// Never shrinks the allocated size.
// The list size is adjusted as per DynamicList with
// SizeInc=0, SizeMult=2, SizeDiv=1
inline void reserve(const label);
//- Clear the list, i.e. set addressable size to zero.
@ -249,7 +255,7 @@ public:
//- Clear the list and delete storage.
inline void clearStorage();
//- Shrink the allocated space to what is used.
//- Shrink the allocated space to what is actually used.
inline void shrink();
//- Transfer the contents of the argument list into this list

View File

@ -810,6 +810,19 @@ inline bool Foam::PackedList<nBits>::set
}
template<unsigned nBits>
inline bool Foam::PackedList<nBits>::unset(const label i)
{
// lazy - ignore out-of-bounds
if (i < 0 || i >= size_)
{
return false;
}
return iteratorBase(this, i).set(0u);
}
template<unsigned nBits>
inline void Foam::PackedList<nBits>::append(const unsigned int val)
{