|
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 (void) noexcept | |
| 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_) |
| 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 |
| bool | empty (void) const |
| const_iterator | end (void) const |
| iterator | end (void) |
| template<hxsize_t capacity_x_> | |
| bool | equal (const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| hxsize_t | erase (const key_t_ &key_) noexcept |
| iterator | erase (iterator pos_) noexcept |
| const mapped_t_ * | find (const key_t_ &key_) const |
| mapped_t_ * | find (const key_t_ &key_) |
| bool | full (void) const |
| const_iterator | get (hxsize_t index_) const |
| iterator | get (hxsize_t index_) |
| iterator | insert (const key_t_ &key_, const mapped_t_ &mapped_) noexcept |
| iterator | insert (const key_t_ &key_, mapped_t_ &&mapped_) noexcept |
| template<hxsize_t capacity_x_> | |
| bool | less (const hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| const_iterator | lower_bound (const key_t_ &key_) const |
| iterator | lower_bound (const key_t_ &key_) |
| hxsize_t | max_size (void) const |
| 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_) |
hxflat_map - A sorted associative container that stores keys and mapped values in two parallel arrays.
Lookup is Θ(log n) via binary search. Insert and erase are Θ(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 |
Destructs the map and destroys all key-value pairs.
|
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.
|
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.
| bool hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::equal | ( | 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.
|
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.
| mapped_t_ * hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::find | ( | const key_t_ & | key_ | ) |
Non-const version of find.
| const mapped_t_ * hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::find | ( | const key_t_ & | key_ | ) | const |
Returns a const pointer to the mapped value for key, or hxnull 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.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::get | ( | hxsize_t | index_ | ) |
Non-const version of get.
| const_iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::get | ( | hxsize_t | index_ | ) | const |
Returns a const iterator to the element at index, or an end iterator if index is out of range.
|
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.
| bool hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::less | ( | 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.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::lower_bound | ( | const key_t_ & | key_ | ) |
Non-const version of lower_bound.
| 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.
|
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.
| iterator hxflat_map< key_t_, mapped_t_, compare_t_, multi_t_, capacity_ >::operator[] | ( | hxsize_t | index_ | ) |
Returns an iterator to the element at index.
Requires index < size().
| 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().
|
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_ | ) |
Non-const version of upper_bound.
| 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.