sincerely Singaporean

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

SGLSet

see header file

(no source file, everything inside header)

template ‹typename T, typename Comparator› class SGLSet;

part of SGEXTN module SG_Containers

set for any type of data

detailed description

list of all including inherited members

implementation details

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

SGLSet();

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

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

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

[[nodiscard]] SGLSet::ConstIterator constIteratorAt(int n) const;

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

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

[[nodiscard]] const T& elementAt(int n) const;

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

bool erase(SGLSet::Iterator& i);

bool erase(const T& x);

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

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

[[nodiscard]] int indexOf(SGLSet::ConstIterator i) const;

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

[[nodiscard]] int indexOf(SGLSet::Iterator i) const;

bool insert(const T& x);

[[nodiscard]] SGLSet::Iterator iteratorAt(int n);

[[nodiscard]] int length() const;

[[nodiscard]] SGLSet::Iterator lowerBound(const T& x);

[[nodiscard]] SGLSet::ConstIterator lowerBound(const T& x) const;

[[nodiscard]] SGLSet::ConstIterator upperBound(const T& x) const;

[[nodiscard]] SGLSet::Iterator upperBound(const T& x);

Detailed Description

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

SGLSet maintains a AVL tree, which is a type of self balancing binary search tree. Most other C++ libraries use a red black tree instead. This makes SGLSet slightly faster than other libraries for accessing elements but slightly slower for modifying the data structure.

SGLSet();

Creates an empty SGLSet.

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

Returns a iterator to the first element in the SGLSet.

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

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

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

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

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

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

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

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

Returns a null constant iterator associated to this SGLSet.

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

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

[[nodiscard]] SGLSet::ConstIterator constIteratorAt(int n) const;

Returns the constant iterator pointing towards the element at index n in the SGLSet.

If n is out of bounds, SGLSet::constEnd is returned.

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

Returns if the SGLSet contains x.

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

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

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

[[nodiscard]] const T& elementAt(int n) const;

Returns the element at index n in the SGLSet.

If n is out of bounds, this is undefined behaviour.

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

Returns a null iterator associated to this SGLSet.

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

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

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

bool erase(SGLSet::Iterator& i);

Removes the element associated with i from the SGLSet.

After the removal, i 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 SGLSet.

This returns false if i is SGLSet::end and true otherwise.

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

bool erase(const T& x);

Removes x from the SGLSet.

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

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

Returns the constant iterator pointing to element x.

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

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

Returns the iterator pointing to element x.

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

[[nodiscard]] int indexOf(SGLSet::ConstIterator i) const;

Returns the index of the element in the SGLSet that i points to.

-1 is returned if i is SGLSet::constEnd.

The index may change if elements are inserted into or removed from SGLSet to keep the SGLSet always sorted.

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

Returns the index of x in the SGLSet.

-1 is returned if x is not in the SGLSet.

The index may change if elements are inserted into or removed from SGLSet to keep the SGLSet always sorted.

[[nodiscard]] int indexOf(SGLSet::Iterator i) const;

Returns the index of the element in the SGLSet that i points to.

-1 is returned if i is SGLSet::end.

The index may change if elements are inserted into or removed from SGLSet to keep the SGLSet always sorted.

bool insert(const T& x);

Inserts x into the SGLSet.

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

[[nodiscard]] SGLSet::Iterator iteratorAt(int n);

Returns the iterator pointing towards the element at index n in the SGLSet.

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

If n is out of bounds, SGLSet::end is returned.

[[nodiscard]] int length() const;

Returns the length of the SGLSet, this is the number of elements stored inside it.

[[nodiscard]] SGLSet::Iterator lowerBound(const T& x);

Returns a iterator to the first element in the SGLSet more than or equal to x.

SGLSet::end is returned if no such iterator exists.

[[nodiscard]] SGLSet::ConstIterator lowerBound(const T& x) const;

Returns a constant iterator to the first element in the SGLSet more than or equal to x.

SGLSet::constEnd is returned if no such iterator exists.

[[nodiscard]] SGLSet::ConstIterator upperBound(const T& x) const;

Returns a constant iterator to the first element in the SGLSet strictly more than x.

SGLSet::constEnd is returned if no such iterator exists.

[[nodiscard]] SGLSet::Iterator upperBound(const T& x);

Returns a iterator to the first element in the SGLSet strictly more than x.

SGLSet::end is returned if no such iterator exists.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects