sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGLUnorderedMultiSet

see header file

(no source file, everything inside header)

template ‹typename T, typename EqualityCheck, typename HashFunction› class SGLUnorderedMultiSet;

part of SGEXTN module SG_Containers

unordered multiset for any type of data

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGLUnorderedMultiSet.h›

CMake target for BuildLah: SGEXTN::SG_Containers

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member functions

SGLUnorderedMultiSet();

[[nodiscard]] SGLUnorderedMultiSet::Iterator begin();

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator constBegin() const;

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator constEnd() const;

[[nodiscard]] bool contains(const T& x) const;

[[nodiscard]] int count(const T& x) const;

[[nodiscard]] SGLUnorderedMultiSet::Iterator end();

bool erase(const T& x);

bool erase(SGLUnorderedMultiSet::Iterator& x);

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator find(const T& x) const;

[[nodiscard]] SGLUnorderedMultiSet::Iterator find(const T& x);

void insert(const T& x);

[[nodiscard]] int length() const;

void reserve(int newMemoryLength);

Detailed Description

SGLUnorderedMultiSet provides a template based unordered multiset that can be used with any data type. Use SGLMultiSet instead if ordering matters. This is a template based class with no separate source file. This class is a SGEXTN container. Copy constructor, copy assignment, move constructor, move assignment, and destructor work as expected. A deep copy is performed whenever this class is copied, and the new instance will not be linked to the old instance in any way. It is assumed that the contents placed into this SGEXTN container can be copied and moved. This means that their copy constructor copy assignment, move constructor, move assignment, and destructor work as expected. If this is not the case or if you want the container to store references or constant references, store pointers instead.

Implementation Details

SGLUnorderedMultiSet maintains an open addressed linear probing hash table with a load factor of 0.33 Due to the extremely low load factor, SGLUnorderedMultiSet is much faster than most implementations of unordered map (especially the Standard Template Library one, which is not even open addressed) at the cost of higher memory usage. The hash table is stored in a C array memory buffer that triples in size when the load factor is reached. SGLUnorderedMultiSet does not store duplicate elements, instead it keeps track of the number of copies of each element using a int, so its internal structure resembles a SGLUnorderedMap‹T, int, EqualityCheck, HashFunction›

SGLUnorderedMultiSet();

Creates an empty SGLUnorderedMultiSet.

[[nodiscard]] SGLUnorderedMultiSet::Iterator begin();

Returns a iterator to the first element in the SGLUnorderedMultiSet.

SGLUnorderedMultiSet iterators behave circularly. This is equivalent to running operator++ on SGLUnorderedMultiSet::end.

SGLUnorderedMultiSet::Iterator allows modifying the SGLUnorderedMultiSet through it. If modification is not needed, use SGLUnorderedMultiSet::ConstIterator instead. The SGLUnorderedMultiSet::ConstIterator equivalent to this function is SGLUnorderedMultiSet::constBegin.

If the SGLUnorderedMultiSet is empty, this is the same as SGLUnorderedMultiSet::end.

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator constBegin() const;

Returns a constant iterator to the first element in the SGLUnorderedMultiSet.

SGLUnorderedMultiSet iterators behave circularly. This is equivalent to running operator++ on SGLUnorderedMultiSet::constEnd.

If the SGLUnorderedMultiSet is empty, this is the same as SGLUnorderedMultiSet::constEnd.

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator constEnd() const;

Returns a null constant iterator associated to this SGLUnorderedMultiSet.

SGLUnorderedMultiSet iterators behave circularly. This is equivalent to running operator-- on SGLUnorderedMultiSet::constBegin.

Attempting to access the element that this iterator points will crash.

[[nodiscard]] bool contains(const T& x) const;

Returns if the SGLUnorderedMultiSet contains any copy of x.

[[nodiscard]] int count(const T& x) const;

Returns the number of copies of x found in the SGLUnorderedMultiSet.

[[nodiscard]] SGLUnorderedMultiSet::Iterator end();

Returns a null iterator associated to this SGLUnorderedMultiSet.

SGLUnorderedMultiSet iterators behave circularly. This is equivalent to running operator-- on SGLUnorderedMultiSet::begin.

SGLUnorderedMultiSet::Iterator allows modifying the SGLUnorderedMultiSet through it. If modification is not needed, use SGLUnorderedMultiSet::ConstIterator instead. The SGLUnorderedMultiSet::ConstIterator equivalent to this function is SGLUnorderedMultiSet::constEnd.

Attempting to access the element that this iterator points to will crash.

bool erase(const T& x);

Removes x from the SGLUnorderedMultiSet.

If there is more than 1 copies of x, the last added copy is removed and other copies remain in the set.

If the SGLUnorderedMultiSet does not contain any copy of x, this will return false, otherwise this returns true.

bool erase(SGLUnorderedMultiSet::Iterator& x);

Removes the element associated with x from the SGLUnorderedMultiSet.

After the removal, x which is passed as a reference, is decremented. This means that you do not have to do any special handling for removed elements when iterating over a SGLUnorderedMultiSet.

This returns false if x is SGLUnorderedMultiSet::end and true otherwise.

Do not write any special logic to modify iterators while removing elements from a SGLUnorderedMultiSet in a loop, SGLUnorderedMultiSet::eraseSGLUnorderedMultiSet::erase handles this for you automatically.

[[nodiscard]] SGLUnorderedMultiSet::ConstIterator find(const T& x) const;

Returns the constant iterator pointing to element x.

SGLUnorderedMultiSet::constEnd is returned if x is not in the SGLUnorderedMultiSet.

[[nodiscard]] SGLUnorderedMultiSet::Iterator find(const T& x);

Returns the iterator pointing to element x.

SGLUnorderedMultiSet::end is returned if x is not in the SGLUnorderedMultiSet.

void insert(const T& x);

Inserts x into the SGLUnorderedMultiSet.

Inserting multiple elements is allowed. If there is already a copy of x, a new copy is added.

[[nodiscard]] int length() const;

Returns the length of the SGLUnorderedMultiSet, which is the number of elements that it contains.

void reserve(int newMemoryLength);

Pre allocates sufficient memory to store (newMemoryLength / 3) - 1 elements without exceeding the load factor.

If sufficient memory is already allocated, this does nothing.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects