|
datastructures 0.1.0
|
A map type using an AVL tree as the underlying structure. More...
#include <map.hpp>
Classes | |
| struct | value_compare |
Public Types | |
| using | key_type = TKey |
| using | mapped_type = TValue |
| using | value_type = std::pair< const key_type, mapped_type > |
| using | reference = value_type & |
| using | const_reference = const value_type & |
| using | key_compare = TKeyComp |
| using | allocator_type = TAlloc |
| using | alloc_traits = std::allocator_traits< allocator_type > |
| using | size_type = typename alloc_traits::size_type |
| using | difference_type = typename alloc_traits::difference_type |
| using | pointer = typename alloc_traits::pointer |
| using | const_pointer = typename alloc_traits::const_pointer |
| using | iterator = detail::avl_iterator< tree_type, false > |
| using | const_iterator = detail::avl_iterator< tree_type, true > |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Public Member Functions | |
| map () | |
| map (const key_compare &comparator, const allocator_type &allocator=allocator_type{}) | |
| map (const allocator_type &allocator) | |
| map (const map &other) | |
| map & | operator= (const map &other) |
| map (map &&other) noexcept | |
| map & | operator= (map &&other) noexcept |
| ~map () noexcept | |
| allocator_type | get_allocator () const noexcept |
| Returns the associated allocator. | |
| key_compare | key_comp () const noexcept |
| Returns the function that compares keys. | |
| value_compare | value_comp () const noexcept |
| Returns the function that compares keys in the key, value pairs. | |
| mapped_type & | at (const key_type &key) |
| Access specified item. | |
| const mapped_type & | at (const key_type &key) const |
| Access specified item. | |
| mapped_type & | operator[] (const key_type &key) |
| Access specified item or insert. | |
| mapped_type & | operator[] (key_type &&key) |
| Access specified item or insert. | |
| iterator | find (const key_type &key) noexcept |
| Finds an item with the given key. | |
| const_iterator | find (const key_type &key) const noexcept |
| Finds an item with the given key. | |
| bool | contains (const key_type &key) const noexcept |
| Checks whether there exists an item with given key in the tree. | |
| size_type | count (const key_type &key) const noexcept |
| Returns the number of items with the given key (0 or 1). | |
| iterator | lower_bound (const key_type &key) noexcept |
| Returns an iterator to the first item which is not less than the given key. | |
| const_iterator | lower_bound (const key_type &key) const noexcept |
| Returns an iterator to the first item which is not less than the given key. | |
| iterator | upper_bound (const key_type &key) noexcept |
| Returns an iterator to the first item which is greater that the given key. | |
| const_iterator | upper_bound (const key_type &key) const noexcept |
| Returns an iterator to the first item which is greater that the given key. | |
| std::pair< iterator, iterator > | equal_range (const key_type &key) noexcept |
| Returns a range containing all the items with the given key. | |
| std::pair< const_iterator, const_iterator > | equal_range (const key_type &key) const noexcept |
| Returns a range containing all the items with the given key. | |
| iterator | begin () noexcept |
| Returns an iterator to the smallest item. | |
| const_iterator | begin () const noexcept |
| Returns an iterator to the smallest item, read only. | |
| const_iterator | cbegin () const noexcept |
| Returns explicitly a constant iterator to the smallest item. | |
| iterator | end () noexcept |
| Returns an iterator to the end. | |
| const_iterator | end () const noexcept |
| Returns an iterator to the end, read only. | |
| const_iterator | cend () const noexcept |
| Returns explicitly a constant iterator to the end. | |
| reverse_iterator | rbegin () noexcept |
| Returns a reverse iterator to the biggest item. | |
| const_reverse_iterator | rbegin () const noexcept |
| Returns a reverse iterator to the biggest item, read only. | |
| const_reverse_iterator | crbegin () const noexcept |
| Returns explicitly a constant reverse iterator to the biggest item. | |
| reverse_iterator | rend () noexcept |
| Returns a reverse iterator to the end. | |
| const_reverse_iterator | rend () const noexcept |
| Returns a reverse iterator to the end, read only. | |
| const_reverse_iterator | crend () const noexcept |
| Returns explicitly a constant reverse iterator to the end. | |
| bool | empty () const noexcept |
| Checks whether the map contains any values. | |
| size_type | size () const noexcept |
| Returns the current number of items. | |
| int | get_height () const noexcept |
| Returns the height of the underlying tree. | |
| void | clear () noexcept |
| Erases the whole tree. | |
| std::pair< iterator, bool > | insert (const value_type &item) |
| Inserts an item. | |
| std::pair< iterator, bool > | insert (value_type &&item) |
| Inserts an item. | |
| template<class TMapped > | |
| std::pair< iterator, bool > | insert_or_assign (const key_type &key, TMapped &&value) |
| Inserts an item or assigns the value. | |
| template<class TMapped > | |
| std::pair< iterator, bool > | insert_or_assign (key_type &&key, TMapped &&value) |
| Inserts an item or assigns the value. | |
| template<class... Args> | |
| std::pair< iterator, bool > | try_emplace (const key_type &key, Args &&...args) |
| Construct an item in-place. | |
| template<class... Args> | |
| std::pair< iterator, bool > | try_emplace (key_type &&key, Args &&...args) |
| Construct an item in-place. | |
| iterator | erase (iterator pos) noexcept |
| Erases an item. | |
| iterator | erase (const_iterator pos) noexcept |
| Erases an item. | |
| size_type | erase (const key_type &key) noexcept |
| Erases an item with the given key. | |
| void | swap (map &other) noexcept |
| Swaps the content. | |
| std::string | to_dot (bool print_invis) const |
| Returns the dot representation of the tree. | |
| template<class TMapped > | |
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > | insert_or_assign (const key_type &key, TMapped &&value) |
| template<class TMapped > | |
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > | insert_or_assign (key_type &&key, TMapped &&value) |
| template<class... Args> | |
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > | try_emplace (const key_type &key, Args &&...args) |
| template<class... Args> | |
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > | try_emplace (key_type &&key, Args &&...args) |
A map type using an AVL tree as the underlying structure.
This map type is mostly compatible with the std::map, but is based on an AVL tree.
When the equivalence relation derived from the TKeyComp has an equivalence class with more than one element, then the first one to be inserted stays there until deleted, in other words the keys are immutable and aren't changed even by assigmnets.
All the references to the items are valid until erased, balancing and inserting new values wont invalidate them.
| TKey | Represents the keys in the map, it must support std::less comparisons or you must provide custom one. |
| TValue | Represents the values, can be anything. |
| TKeyComp | The comparison struct, it must contain operator() which takes two keys as parameters and creates a weak ordering on them. |
| TAlloc | The allocator that can allocate the key, value pairs, must comply with the standard allocators, so that std::allocator_traits works on it. Internally it is rebinded to allocate the nodes themself. |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::alloc_traits = std::allocator_traits<allocator_type> |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::allocator_type = TAlloc |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::const_iterator = detail::avl_iterator<tree_type, true> |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::const_pointer = typename alloc_traits::const_pointer |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::const_reference = const value_type & |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::difference_type = typename alloc_traits::difference_type |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::iterator = detail::avl_iterator<tree_type, false> |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::key_compare = TKeyComp |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::key_type = TKey |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::mapped_type = TValue |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::pointer = typename alloc_traits::pointer |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::reference = value_type & |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::reverse_iterator = std::reverse_iterator<iterator> |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::size_type = typename alloc_traits::size_type |
| using datastructures::map< TKey, TValue, TKeyComp, TAlloc >::value_type = std::pair<const key_type, mapped_type> |
| datastructures::map< TKey, TValue, TKeyComp, TAlloc >::map | ( | ) |
|
explicit |
|
explicit |
| datastructures::map< TKey, TValue, TKeyComp, TAlloc >::map | ( | const map< TKey, TValue, TKeyComp, TAlloc > & | other | ) |
|
noexcept |
| map< TKey, TValue, TKeyComp, TAlloc >::mapped_type & datastructures::map< TKey, TValue, TKeyComp, TAlloc >::at | ( | const key_type & | key | ) |
Access specified item.
When there is no item with the specified key throws std::out_of_range.
| const map< TKey, TValue, TKeyComp, TAlloc >::mapped_type & datastructures::map< TKey, TValue, TKeyComp, TAlloc >::at | ( | const key_type & | key | ) | const |
Access specified item.
A constant overload. When there is no item with the specified key throws std::out_of_range.
|
noexcept |
Returns an iterator to the smallest item, read only.
|
noexcept |
Returns an iterator to the smallest item.
|
noexcept |
Returns explicitly a constant iterator to the smallest item.
|
noexcept |
Returns explicitly a constant iterator to the end.
|
noexcept |
Checks whether there exists an item with given key in the tree.
|
noexcept |
Returns the number of items with the given key (0 or 1).
|
noexcept |
Returns explicitly a constant reverse iterator to the biggest item.
|
noexcept |
Returns explicitly a constant reverse iterator to the end.
Checks whether the map contains any values.
|
noexcept |
Returns an iterator to the end, read only.
|
noexcept |
Returns an iterator to the end.
|
noexcept |
Returns a range containing all the items with the given key.
Returns a pair containing the lower and upper bounds.
std::pair constaining a pair of iterator. For each element of the pair, if there is no such item present a past-the-end iterator is returned at its place.
|
noexcept |
Returns a range containing all the items with the given key.
Returns a pair containing the lower and upper bounds.
std::pair constaining a pair of iterator. For each element of the pair, if there is no such item present a past-the-end iterator is returned at its place.
|
noexcept |
Erases an item with the given key.
Does nothing when the key does not exist.
|
noexcept |
|
noexcept |
Finds an item with the given key.
|
noexcept |
Finds an item with the given key.
|
noexcept |
Returns the associated allocator.
Returns the height of the underlying tree.
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert | ( | const value_type & | item | ) |
Inserts an item.
Tries to insert an item into the tree, when there already is an item with the given key does nothing. Returns true if and only if the insertion was performed. Copies the key, value pair.
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert | ( | value_type && | item | ) |
Inserts an item.
Tries to insert an item into the tree, when there already is an item with the given key does nothing. Returns true if and only if the insertion was performed. Moves the key, value pair, if the insertion does not happen the values data are not invalidated.
| std::pair< iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert_or_assign | ( | const key_type & | key, |
| TMapped && | value | ||
| ) |
Inserts an item or assigns the value.
If a key equivalent to key already exists, assigns std::forward<M>(value) to the value belonging to key. Otherwise inserts a new value, constructing it from value_type(key, std::forward<M>(value)).
true if the item was inserted, false if it was updated.| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert_or_assign | ( | const key_type & | key, |
| TMapped && | value | ||
| ) |
| std::pair< iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert_or_assign | ( | key_type && | key, |
| TMapped && | value | ||
| ) |
Inserts an item or assigns the value.
If a key equivalent to key already exists, assigns std::forward<M>(value) to the value belonging to key and the keys data are not invalidated. Otherwise inserts a new value, constructing it from value_type(std::move(key), std::forward<M>(value)).
true if the item was inserted, false if it was updated.| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::insert_or_assign | ( | key_type && | key, |
| TMapped && | value | ||
| ) |
|
noexcept |
Returns the function that compares keys.
|
noexcept |
Returns an iterator to the first item which is not less than the given key.
The key doesn't have to be in the tree.
|
noexcept |
Returns an iterator to the first item which is not less than the given key.
The key doesn't have to be in the tree.
| map< TKey, TValue, TKeyComp, TAlloc > & datastructures::map< TKey, TValue, TKeyComp, TAlloc >::operator= | ( | const map< TKey, TValue, TKeyComp, TAlloc > & | other | ) |
|
noexcept |
| map< TKey, TValue, TKeyComp, TAlloc >::mapped_type & datastructures::map< TKey, TValue, TKeyComp, TAlloc >::operator[] | ( | const key_type & | key | ) |
Access specified item or insert.
Returns a reference to the mapped value performing an insertion when the specified key isn't present.
| map< TKey, TValue, TKeyComp, TAlloc >::mapped_type & datastructures::map< TKey, TValue, TKeyComp, TAlloc >::operator[] | ( | key_type && | key | ) |
Access specified item or insert.
Returns a reference to the mapped value performing an insertion when the specified key isn't present. In this overload the key will be moved in the case of a new insertion.
|
noexcept |
Returns a reverse iterator to the biggest item, read only.
|
noexcept |
Returns a reverse iterator to the biggest item.
|
noexcept |
Returns a reverse iterator to the end, read only.
|
noexcept |
Returns a reverse iterator to the end.
|
noexcept |
Returns the current number of items.
Returns the dot representation of the tree.
| std::pair< iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::try_emplace | ( | const key_type & | key, |
| Args &&... | args | ||
| ) |
Construct an item in-place.
If there is no item with the given key, inserts a new item into the tree constructed in-place with the given args, otherwise does nothing.
The arguments are forwarded using std::forward<Args>(args)... into the constructor to retain their original types.
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::try_emplace | ( | const key_type & | key, |
| Args &&... | args | ||
| ) |
| std::pair< iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::try_emplace | ( | key_type && | key, |
| Args &&... | args | ||
| ) |
Construct an item in-place.
If there is no item with the given key, inserts a new item into the tree constructed in-place with the given args, otherwise does nothing.
The arguments are forwarded using std::forward<Args>(args)... into the constructor to retain their original types. The key is also moved in this overload.
| std::pair< typename map< TKey, TValue, TKeyComp, TAlloc >::iterator, bool > datastructures::map< TKey, TValue, TKeyComp, TAlloc >::try_emplace | ( | key_type && | key, |
| Args &&... | args | ||
| ) |
|
noexcept |
Returns an iterator to the first item which is greater that the given key.
The key doesn't have to be in the tree.
|
noexcept |
Returns an iterator to the first item which is greater that the given key.
The key doesn't have to be in the tree.
|
noexcept |
Returns the function that compares keys in the key, value pairs.