CMagic
0.5.0
Portable C library of utilities and data structures
|
A container that stores unique elements following a specific order. More...
#include <set.hpp>
Classes | |
class | iterator |
Public Types | |
using | value_type = T |
Type of set elements. More... | |
using | size_type = size_t |
Type used to measure element size. More... | |
Public Member Functions | |
set () | |
Constructs an empty set with standard memory allocation. More... | |
operator bool () const | |
Checks if the set is properly initialized. More... | |
iterator | begin () const |
Return iterator to beginning. More... | |
iterator | end () const |
Return iterator to end. More... | |
void | clear () |
Removes all elements from the set, leaving the container with a size of 0. More... | |
std::pair< iterator, bool > | insert (const value_type &val) |
Inserts a new element to the set if it is not equivalent to any element already contained in the set. More... | |
std::pair< iterator, bool > | insert (value_type &&val) |
Inserts a new element to the set if it is not equivalent to any element already contained in the set. More... | |
void | erase (const value_type &val) |
Removes a single element from the set. More... | |
size_type | size () const |
Returns the number of elements in the set. More... | |
bool | empty () const |
Returns whether the set is empty (i.e. whether its size is 0). More... | |
iterator | find (const value_type &val) const |
Searches the container for an element equivalent to val and returns an iterator to it if found, otherwise it returns set::end. More... | |
Static Public Member Functions | |
static set | custom_allocation_set () |
Constructs an empty set using custom CMagic memory allocation from memory.h. More... | |
A container that stores unique elements following a specific order.
Each value in the set is unique. The value of the elements in a set cannot be modified once in the container but they can be inserted or removed from the container. Set is implemented as an AVL tree.
using cmagic::set< T >::size_type = size_t |
Type used to measure element size.
using cmagic::set< T >::value_type = T |
Type of set elements.
|
inline |
Constructs an empty set with standard memory allocation.
|
inline |
Return iterator to beginning.
Returns an iterator pointing to the first element in the set. If the container is empty, the returned iterator value shall not be dereferenced.
|
inline |
Removes all elements from the set, leaving the container with a size of 0.
|
inlinestatic |
Constructs an empty set using custom CMagic memory allocation from memory.h.
|
inline |
Returns whether the set is empty (i.e. whether its size is 0).
This function does not modify the container in any way. To clear the content of a set, see set::clear.
true
if the container size is 0, false
otherwise
|
inline |
Return iterator to end.
It does not point to any element, and thus shall not be dereferenced.
|
inline |
Removes a single element from the set.
val | value to be removed from the set. Function does nothing if the element doesn't exist in the set. |
|
inline |
|
inline |
Inserts a new element to the set if it is not equivalent to any element already contained in the set.
Because elements in a set are unique, the insertion operation checks whether an inserted element is equivalent to an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element.
val | value to be copied (or moved) to the set |
pair::first
set to an iterator pointing to either the newly inserted element or to the equivalent element already in the set or end if allocation of the new element has failed. The pair::second
element in the pair is set to true
if a new element was inserted or false
if an equivalent element already existed (or could not be inserted due to allocation failure).
|
inline |
Inserts a new element to the set if it is not equivalent to any element already contained in the set.
Because elements in a set are unique, the insertion operation checks whether an inserted element is equivalent to an element already in the container, and if so, the element is not inserted, returning an iterator to this existing element.
val | value to be copied (or moved) to the set |
pair::first
set to an iterator pointing to either the newly inserted element or to the equivalent element already in the set or end if allocation of the new element has failed. The pair::second
element in the pair is set to true
if a new element was inserted or false
if an equivalent element already existed (or could not be inserted due to allocation failure).
|
inline |
Checks if the set is properly initialized.
Example usage:
true
if set is initialized, false
if set allocation has failed and no operation should be made on it
|
inline |
Returns the number of elements in the set.