sincerely Singaporean

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

SGLUnorderedSet

see header file

(no source file, everything inside header)

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

part of SGEXTN module SG_Containers

unordered set for any type of data

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGLUnorderedSet.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

SGLUnorderedSet();

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

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

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

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

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

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

bool erase(SGLUnorderedSet::Iterator& x);

bool erase(const T& x);

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

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

bool insert(const T& x);

[[nodiscard]] int length() const;

void reserve(int newMemoryLength);

Detailed Description

SGLUnorderedSet provides a template based unordered set that can be used with any data type. Use SGLSet 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

SGLUnorderedSet maintains an open addressed linear probing hash table with a load factor of 0.33 Due to the extremely low load factor, SGLUnorderedSet 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.

SGLUnorderedSet();

Creates an empty SGLUnorderedSet.

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

Returns a iterator to the first element in the SGLUnorderedSet.

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

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

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

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

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

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

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

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

Returns a null constant iterator associated to this SGLUnorderedSet.

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

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

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

Returns if the SGLUnorderedSet contains x.

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

Returns the number of copies of x in the SGLUnorderedSet, this is either 0 or 1.

This has identical functionality to SGLUnorderedSet::contains, it is included for API consistency.

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

Returns a null iterator associated to this SGLUnorderedSet.

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

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

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

bool erase(SGLUnorderedSet::Iterator& x);

Removes the element associated with x from the SGLUnorderedSet.

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 SGLUnorderedSet.

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

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

bool erase(const T& x);

Removes x from the SGLUnorderedSet.

If the SGLUnorderedSet does not contain x, this function will return false, otherwise this returns true.

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

Returns the constant iterator pointing to element x.

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

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

Returns the iterator pointing to element x.

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

bool insert(const T& x);

Inserts x into the SGLUnorderedSet.

If the SGLUnorderedSet already contains x, this function will return false, otherwise this returns true.

[[nodiscard]] int length() const;

Returns the length of the SGLUnorderedSet, which is the number of elements currently stored in the SGLUnorderedSet.

void reserve(int newMemoryLength);

Pre allocates enough memory to store (newMemoryLength / 3) - 1 elements in the SGLUnorderedSet without resizing.

If the existing memory is sufficient, this does nothing.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects