sincerely Singaporean

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

SGLMap

see header file

(no source file, everything inside header)

template ‹typename K, typename V, typename Comparator› class SGLMap;

part of SGEXTN module SG_Containers

ordered map for any type of data

detailed description

list of all including inherited members

implementation details

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

SGLMap();

[[nodiscard]] V& at(const K& x);

[[nodiscard]] const V& at(const K& x) const;

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

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

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

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

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

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

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

bool erase(const K& x);

bool erase(SGLMap::Iterator& i);

[[nodiscard]] SGLMap::ConstIterator find(const K& x) const;

[[nodiscard]] SGLMap::Iterator find(const K& x);

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

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

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

bool insert(const K& xKey, const V& xValue);

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

[[nodiscard]] const K& keyAt(int n) const;

[[nodiscard]] int length() const;

[[nodiscard]] SGLMap::Iterator lowerBound(const K& x);

[[nodiscard]] SGLMap::ConstIterator lowerBound(const K& x) const;

[[nodiscard]] SGLMap::ConstIterator upperBound(const K& x) const;

[[nodiscard]] SGLMap::Iterator upperBound(const K& x);

[[nodiscard]] V& valueAt(int n);

Detailed Description

SGLMap provides a template based ordered map that can be used with any data type. Use SGLUnorderedMap instead if order does not matter. SGEXTN does not provide any multimap so you must use a SGLMap‹K, SGLVector‹V››. 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

SGLMap 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 SGLMap slightly faster than other libraries for accessing elements but slightly slower for modifying the data structure.

SGLMap();

Creates an empty SGLMap.

[[nodiscard]] V& at(const K& x);

Returns a reference to the value associated with key x in the SGLMap.

Since this returns a reference and not a copy, assigning to it directly (using it as a lvalue) would modify the SGLMap.

This will crash if x is not in the SGLMap. Use SGLMap::contains to check if x is in the SGLMap if unsure.

[[nodiscard]] const V& at(const K& x) const;

Returns a constant reference to the value associated with key x in the SGLMap.

This will crash if x is not in the SGLMap. Use SGLMap::contains to check if x is in the SGLMap if unsure.

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

Returns a iterator to the first key value pair in the SGLMap.

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

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

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

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

Returns a constant iterator to the first key value pair in the SGLMap.

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

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

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

Returns a null constant iterator associated to this SGLMap.

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

Attempting to access the key or value that this iterator points to will crash.

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

Returns the constant iterator pointing towards the key value pair, the key of which is at index n in the SGLMap.

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

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

Returns if the SGLMap contains x as a key

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

Returns the number of copies of the key x is found inside the SGLMap.

This is either 0 or 1, functionally identical to SGLMap::contains. It is provided purely for API consistency.

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

Returns a null iterator associated to this SGLMap.

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

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

Attempting to access the key or value that this iterator points to will crash.

bool erase(const K& x);

Removes the key x and its associated value from the SGLMap.

If x is not in the SGLMap, this will return false, otherwise this returns true.

bool erase(SGLMap::Iterator& i);

Removes the key value pair associated with i from the SGLMap.

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

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

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

[[nodiscard]] SGLMap::ConstIterator find(const K& x) const;

Returns the constant iterator pointing to key x.

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

[[nodiscard]] SGLMap::Iterator find(const K& x);

Returns the iterator pointing to key x.

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

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

Returns the index of the key value pair in the SGLMap that i points to.

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

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

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

Returns the index of the key value pair in the SGLMap that i points to.

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

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

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

Returns the index of the key value pair with key x in the SGLMap.

-1 is returned if the key x is not in the SGLMap.

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

bool insert(const K& xKey, const V& xValue);

Inserts the key value pair (xKey, xValue) into the SGLMap.

If xKey already exists in the SGLMap, this will return false, otherwise this returns true.

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

Returns the iterator pointing towards the key value pair, the key of which is at index n in the SGLMap.

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

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

[[nodiscard]] const K& keyAt(int n) const;

Returns the key at index n in the SGLMap.

If n is out of bounds, this will crash.

[[nodiscard]] int length() const;

Returns the length of the SGLMap, which is the number of elements currently stored inside it.

[[nodiscard]] SGLMap::Iterator lowerBound(const K& x);

Returns a iterator to the first key value pair in the SGLMap with a key more than or equal to x.

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

[[nodiscard]] SGLMap::ConstIterator lowerBound(const K& x) const;

Returns a constant iterator to the first key value pair in the SGLMap with a key more than or equal to x.

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

[[nodiscard]] SGLMap::ConstIterator upperBound(const K& x) const;

Returns a constant iterator to the first key value pair in the SGLMap with a key strictly more than x.

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

[[nodiscard]] SGLMap::Iterator upperBound(const K& x);

Returns a iterator to the first key value pair in the SGLMap with a key strictly more than x.

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

[[nodiscard]] V& valueAt(int n);

Returns the value associated with the key at index n in the SGLMap.

The value is returned as a reference and not a copy. Assigning to it (using it as a lvalue) modifies the SGLMap.

If n is out of bounds, this will crash.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects