Commit d2d39c32 authored by Mark Olesen's avatar Mark Olesen
Browse files

HashSet and PackedList get an unset() method

- provides a convenient (and lazy) means of removing entries
parent 16c715ce
......@@ -58,9 +58,15 @@ int main(int argc, char *argv[])
list1.print(Info);
Info<< "\ntest set() with default argument (max_value)\n";
list1.set(1);
list1.set(3);
list1.print(Info);
Info<< "\ntest unset() with in-range and out-of-range\n";
list1.unset(3);
list1.unset(100000);
list1.print(Info);
Info<< "\ntest assign between references\n";
list1[2] = 3;
list1[4] = list1[2];
......
......@@ -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
......
......@@ -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
......
......@@ -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)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment