|
libhatchet
|
#include <hxflat_map.hpp>
Classes | |
| class | const_iterator |
| class | iterator |
Public Types | |
| using | key_t = key_t_ |
| using | mapped_t = mapped_t_ |
| using | compare_t = compare_t_ |
Public Member Functions | |
| hxflat_map (void) | |
| hxflat_map (const hxflat_map &x_) noexcept | |
| hxflat_map (hxflat_map &&x_) noexcept | |
| hxflat_map (std::initializer_list< pair_t_ > x_) noexcept | |
| ~hxflat_map (void) noexcept | |
| template<typename self_t_, typename callable_t_> | |
| auto | and_then (this self_t_ &&self_, const key_t_ &key_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< mapped_t_ & >())))> |
| template<typename self_t_, typename callable_t_> | |
| auto | and_then (this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< const mapped_t_ & >())))> |
| void | operator= (const hxflat_map &x_) noexcept |
| template<hxsize_t capacity_x_> | |
| void | operator= (const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) noexcept |
| void | operator= (hxflat_map &&x_) noexcept |
| const_iterator | operator[] (hxsize_t index_) const |
| iterator | operator[] (hxsize_t index_) |
| template<hxsize_t capacity_x_> | |
| bool | operator== (const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| template<hxsize_t capacity_x_> | |
| bool | operator< (const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| const_iterator | begin (void) const |
| iterator | begin (void) |
| hxsize_t | capacity (void) const |
| const_iterator | cbegin (void) const |
| const_iterator | cend (void) const |
| void | clear (void) noexcept |
| hxsize_t | count (const key_t_ &key_) const |
| template<typename... args_t_> | |
| iterator | emplace (const key_t_ &key_, args_t_ &&... args_) noexcept |
| bool | empty (void) const |
| const_iterator | end (void) const |
| iterator | end (void) |
| hxsize_t | erase (const key_t_ &key_) noexcept |
| iterator | erase (const_iterator it_) noexcept |
| const_iterator | find (const key_t_ &key_) const |
| iterator | find (const key_t_ &key_) |
| bool | full (void) const |
| bool | has_value (const key_t_ &key_) const |
| iterator | insert (const key_t_ &key_, const mapped_t_ &mapped_) noexcept |
| iterator | insert (const key_t_ &key_, mapped_t_ &&mapped_) noexcept |
| const key_t_ * | keys (void) const noexcept |
| const_iterator | lower_bound (const key_t_ &key_) const |
| iterator | lower_bound (const key_t_ &key_) |
| hxsize_t | max_size (void) const |
| template<typename self_t_, typename callable_t_> | |
| auto | or_else (this self_t_ &&self_, const key_t_ &key_, callable_t_ &&callable_) -> decltype(self_.end()) |
| template<typename self_t_, typename callable_t_> | |
| auto | or_else (this self_t_ &&self_, const_iterator it_, callable_t_ &&callable_) -> decltype(self_.end()) |
| void | reserve (hxsize_t cap_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) noexcept |
| hxsize_t | size (void) const |
| void | swap (hxflat_map &x_) noexcept |
| const_iterator | upper_bound (const key_t_ &key_) const |
| iterator | upper_bound (const key_t_ &key_) |
| template<typename self_t_, typename... args_t_> | |
| mapped_t_ | value_or (this self_t_ &&self_, const key_t_ &key_, args_t_ &&... args_) |
| template<typename self_t_, typename... args_t_> | |
| mapped_t_ | value_or (this self_t_ &&self_, const_iterator it_, args_t_ &&... args_) |
| const mapped_t_ * | values (void) const noexcept |
| mapped_t_ * | values (void) noexcept |
hxflat_map - A sorted associative container that stores keys and mapped values in two parallel arrays.
Lookup is O(log n) via binary search. Insert and erase are O(n) because elements are shifted to maintain order. This design keeps keys and values cache-friendly and avoids heap overhead per element.
When multi_t is false duplicate keys are rejected and insert returns an iterator to the existing element. When multi_t is true duplicate keys are always inserted. compare_t must be a callable with signature bool(const key_t_&, const key_t_&) returning true when the first argument is ordered before the second. It defaults to hxkey_less_t.
When capacity is hxallocator_dynamic_capacity storage must be allocated by calling reserve before inserting elements. Otherwise the arrays are statically sized to capacity elements and reserve may only be called with exactly that value.
E.g.:
| using hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::compare_t = compare_t_ |
| using hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::key_t = key_t_ |
| using hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::mapped_t = mapped_t_ |
|
explicit |
Constructs an empty map.
Requires reserve before inserting when capacity is hxallocator_dynamic_capacity.
|
noexcept |
Copy constructs from another hxflat_map.
Requires x.size() ≤ capacity().
|
noexcept |
Move constructs from a temporary hxflat_map.
Requires hxallocator_dynamic_capacity.
|
noexcept |
|
noexcept |
Destructs the map and destroys all key-value pairs.
| auto hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::and_then | ( | this self_t_ && | self_, |
| const key_t_ & | key_, | ||
| callable_t_ && | callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< mapped_t_ & >())))> |
Returns the result of calling callable with the mapped value for the first key matching key, otherwise returns hxnil.
Use and_then to return hxptr, hxref or hxexpected.
| auto hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::and_then | ( | this self_t_ && | self_, |
| const_iterator | it_, | ||
| callable_t_ && | callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< constmapped_t_ & >())))> |
|
inline |
Returns an iterator pointing to the first element.
|
inline |
Returns a const iterator pointing to the first element.
|
inline |
Returns the number of elements the map can hold.
|
inline |
Returns a const iterator pointing to the first element (alias for begin).
|
inline |
Returns a const iterator pointing past the last element.
|
noexcept |
Removes all elements and destroys their key-value pairs.
| hxsize_t hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::count | ( | const key_t_ & | key_ | ) | const |
Returns the number of elements with the given key.
|
noexcept |
Constructs and inserts a mapped value from args, returning an iterator to the new or existing element.
|
inline |
Checks if the map contains no elements.
|
inline |
Returns an iterator pointing past the last element.
|
inline |
Returns a const iterator pointing past the last element.
|
noexcept |
Removes all elements with the given key and destroys their key-value pairs.
Returns the number of elements removed.
|
noexcept |
Removes the element at the iterator position and destroys the key-value pair.
Returns an iterator to the element that followed the erased one.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::find | ( | const key_t_ & | key_ | ) |
| const_iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::find | ( | const key_t_ & | key_ | ) | const |
Returns a const iterator to key, or end() if the key is not found.
When multi_t is true the first match is returned.
|
inline |
Returns true if the map has reached its capacity.
| bool hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::has_value | ( | const key_t_ & | key_ | ) | const |
Returns true if an element matching key exists.
|
noexcept |
Inserts a key-value pair.
When multi_t is false and a matching key already exists, returns an iterator to the existing element without inserting. Otherwise inserts in sorted order and returns an iterator to the new element.
|
noexcept |
Move-value overload of insert.
|
noexcept |
Returns a const pointer to the underlying key storage.
Only the first size() elements are constructed.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::lower_bound | ( | const key_t_ & | key_ | ) |
| const_iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::lower_bound | ( | const key_t_ & | key_ | ) | const |
Returns an iterator to the first element whose key is not ordered before key.
Returns end if no such element exists.
|
inline |
Returns the capacity of the map.
| bool hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::operator< | ( | const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > & | x_ | ) | const |
Returns true if this map compares less than x lexicographically, using hxkey_equal and hxkey_less on keys and values.
|
noexcept |
Assigns the contents of x to this map.
Clears this map then copies all elements from x. Requires x.size() ≤ capacity().
|
noexcept |
Cross-capacity copy assignment.
Assigns the contents of x to this map. Requires x.size() ≤ capacity().
|
noexcept |
Move assigns from a temporary map using swap.
Requires hxallocator_dynamic_capacity.
| bool hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::operator== | ( | const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > & | x_ | ) | const |
Returns true if this map and x contain the same key-value pairs in the same order using hxkey_equal on both keys and values.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::operator[] | ( | hxsize_t | index_ | ) |
| const_iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::operator[] | ( | hxsize_t | index_ | ) | const |
Returns a const iterator to the element at index.
Requires index < size().
| auto hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::or_else | ( | this self_t_ && | self_, |
| const key_t_ & | key_, | ||
| callable_t_ && | callable_ )->decltype(self_.end()) |
Returns an iterator to the first element matching key, or the result of calling callable when lookup fails.
| auto hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::or_else | ( | this self_t_ && | self_, |
| const_iterator | it_, | ||
| callable_t_ && | callable_ )->decltype(self_.end()) |
|
noexcept |
Allocates storage for cap keys and values.
When capacity is fixed, cap must equal capacity. Reallocation is not allowed.
|
inline |
Returns the number of elements in the map.
|
noexcept |
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::upper_bound | ( | const key_t_ & | key_ | ) |
| const_iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::upper_bound | ( | const key_t_ & | key_ | ) | const |
Returns an iterator to the first element whose key is ordered after key.
Returns end if no such element exists.
| mapped_t_ hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::value_or | ( | this self_t_ && | self_, |
| const key_t_ & | key_, | ||
| args_t_ &&... | args_ ) |
Returns a copy of the mapped value for the first key matching key, or a mapped value constructed from args when lookup fails.
| mapped_t_ hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::value_or | ( | this self_t_ && | self_, |
| const_iterator | it_, | ||
| args_t_ &&... | args_ ) |
|
noexcept |
Returns a const pointer to the underlying mapped value storage.
Only the first size() elements are constructed.
|
noexcept |