mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
HashSet and PackedList get an unset() method
- provides a convenient (and lazy) means of removing entries
This commit is contained in:
@ -58,9 +58,15 @@ int main(int argc, char *argv[])
|
|||||||
list1.print(Info);
|
list1.print(Info);
|
||||||
|
|
||||||
Info<< "\ntest set() with default argument (max_value)\n";
|
Info<< "\ntest set() with default argument (max_value)\n";
|
||||||
|
list1.set(1);
|
||||||
list1.set(3);
|
list1.set(3);
|
||||||
list1.print(Info);
|
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";
|
Info<< "\ntest assign between references\n";
|
||||||
list1[2] = 3;
|
list1[2] = 3;
|
||||||
list1[4] = list1[2];
|
list1[4] = list1[2];
|
||||||
|
|||||||
@ -136,6 +136,12 @@ public:
|
|||||||
return insert(lst);
|
return insert(lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Unset the specified key - same as erase
|
||||||
|
bool unset(const Key& key)
|
||||||
|
{
|
||||||
|
return HashTable<nil, Key, Hash>::erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
|
|||||||
@ -201,6 +201,10 @@ public:
|
|||||||
// Default value set is the max_value.
|
// Default value set is the max_value.
|
||||||
inline bool set(const label, const unsigned int val = ~0u);
|
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
|
//- Return the underlying packed storage
|
||||||
inline List<unsigned int>& storage();
|
inline List<unsigned int>& storage();
|
||||||
|
|
||||||
@ -240,6 +244,8 @@ public:
|
|||||||
|
|
||||||
//- Reserve allocation space for at least this size.
|
//- Reserve allocation space for at least this size.
|
||||||
// Never shrinks the allocated 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);
|
inline void reserve(const label);
|
||||||
|
|
||||||
//- Clear the list, i.e. set addressable size to zero.
|
//- Clear the list, i.e. set addressable size to zero.
|
||||||
@ -249,7 +255,7 @@ public:
|
|||||||
//- Clear the list and delete storage.
|
//- Clear the list and delete storage.
|
||||||
inline void clearStorage();
|
inline void clearStorage();
|
||||||
|
|
||||||
//- Shrink the allocated space to what is used.
|
//- Shrink the allocated space to what is actually used.
|
||||||
inline void shrink();
|
inline void shrink();
|
||||||
|
|
||||||
//- Transfer the contents of the argument list into this list
|
//- 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>
|
template<unsigned nBits>
|
||||||
inline void Foam::PackedList<nBits>::append(const unsigned int val)
|
inline void Foam::PackedList<nBits>::append(const unsigned int val)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user