|
libhatchet
|
#include <hxflat_set.hpp>
Public Types | |
| using | key_t = key_t_ |
| using | compare_t = compare_t_ |
| using | iterator = const key_t_* |
| using | const_iterator = const key_t_* |
Public Member Functions | |
| hxflat_set (void) | |
| hxflat_set (const hxflat_set &x_) noexcept | |
| hxflat_set (hxflat_set &&x_) noexcept | |
| hxflat_set (std::initializer_list< key_t_ > x_) noexcept | |
| ~hxflat_set (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< const key_t_ & >())))> |
| template<typename self_t_, typename callable_t_> | |
| auto | and_then (this self_t_ &&self_, const key_t_ *it_, callable_t_ &&callable_) -> hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< const key_t_ & >())))> |
| void | operator= (const hxflat_set &x_) noexcept |
| template<hxsize_t capacity_x_> | |
| void | operator= (const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > &x_) noexcept |
| void | operator= (hxflat_set &&x_) noexcept |
| const key_t_ * | operator[] (hxsize_t index_) const |
| template<hxsize_t capacity_x_> | |
| bool | operator== (const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| template<hxsize_t capacity_x_> | |
| bool | operator< (const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| template<hxrange_concept_ range_t_> | |
| void | add_range (range_t_ &range_) noexcept |
| template<hxrange_concept_ range_t_, hxenable_if_t<!hxis_lvalue_reference< range_t_ >(), int > = 0> | |
| void | add_range (range_t_ &&range_) noexcept |
| const key_t_ * | begin (void) const |
| hxsize_t | capacity (void) const |
| const key_t_ * | cbegin (void) const |
| const key_t_ * | cend (void) const |
| void | clear (void) noexcept |
| hxsize_t | count (const key_t_ &key_) const |
| template<typename... args_t_> | |
| const key_t_ * | emplace (args_t_ &&... args_) noexcept |
| bool | empty (void) const |
| const key_t_ * | end (void) const |
| hxsize_t | erase (const key_t_ &key_) noexcept |
| const key_t_ * | erase (const key_t_ *it_) noexcept |
| const key_t_ * | find (const key_t_ &key_) const |
| bool | full (void) const |
| bool | has_value (const key_t_ &key_) const |
| const key_t_ * | insert (const key_t_ &key_) noexcept |
| const key_t_ * | insert (key_t_ &&key_) noexcept |
| const key_t_ * | keys (void) const noexcept |
| const key_t_ * | lower_bound (const key_t_ &key_) const |
| 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 key_t_ *it_, callable_t_ &&callable_) -> decltype(self_.end()) |
| void | reserve (hxsize_t cap_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) |
| hxsize_t | size (void) const |
| void | swap (hxflat_set &x_) noexcept |
| const key_t_ * | upper_bound (const key_t_ &key_) const |
| template<typename self_t_, typename... args_t_> | |
| key_t_ | value_or (this self_t_ &&self_, const key_t_ &key_, args_t_ &&... args_) |
| template<typename self_t_, typename... args_t_> | |
| key_t_ | value_or (this self_t_ &&self_, const key_t_ *it_, args_t_ &&... args_) |
hxflat_set - A sorted associative container that stores keys in a single array.
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 cache-friendly and avoids heap overhead per element.
When multi_t is false duplicate keys are rejected and insert returns a pointer 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 array is statically sized to capacity elements and reserve may only be called with exactly that value. extract() is not provided, just use data().
E.g.:
| using hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::compare_t = compare_t_ |
| using hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::const_iterator = const key_t_* |
const_iterator - Const random access iterator over keys.
| using hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::iterator = const key_t_* |
iterator - Const random access iterator over keys.
| using hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::key_t = key_t_ |
|
explicit |
Constructs an empty set.
Requires reserve before inserting when capacity is hxallocator_dynamic_capacity.
|
noexcept |
Copy constructs from another hxflat_set.
Requires x.size() ≤ capacity().
|
noexcept |
Move constructs from a temporary hxflat_set.
Requires hxallocator_dynamic_capacity.
|
noexcept |
|
noexcept |
Destructs the set and destroys all keys.
|
noexcept |
Inserts every key from a temporary range by moving each key with insert.
This overload enables moving the range keys into the set when forwarding rvalues.
|
noexcept |
Inserts every key from a range referenced by an lvalue by copying each key with insert.
| auto hxflat_set< key_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< constkey_t_ & >())))> |
Returns the result of calling callable with the first key matching key, otherwise returns hxnil.
Use and_then to return hxptr, hxref or hxexpected.
| auto hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::and_then | ( | this self_t_ && | self_, |
| const key_t_ * | it_, | ||
| callable_t_ && | callable_ )->hxremove_cvref_t< decltype(hxforward< callable_t_ >(callable_)(hxforward_like< self_t_ >(hxdeclval< constkey_t_ & >())))> |
|
inline |
Returns a const pointer to the first element.
| hxsize_t hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::capacity | ( | void | ) | const |
Returns the capacity of the set or 0 if unallocated.
|
inline |
Returns a const pointer to the first element (alias for begin).
|
inline |
Returns a const pointer past the last element.
|
noexcept |
Removes all elements and destroys their keys.
| hxsize_t hxflat_set< key_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 key from args, returning a pointer to the new or existing key.
|
inline |
Checks if the set contains no elements.
|
inline |
Returns a const pointer past the last element.
|
noexcept |
Removes all elements with the given key and destroys their keys.
Returns the number of elements removed.
|
noexcept |
Removes the element at the pointer position and destroys the key.
Returns a const pointer to the element that followed the erased one.
| const key_t_ * hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::find | ( | const key_t_ & | key_ | ) | const |
Returns a const pointer to the key if found, or end() if not present.
When multi_t is true the first match is returned.
|
inline |
Returns true if the set has reached its capacity.
| bool hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::has_value | ( | const key_t_ & | key_ | ) | const |
Returns true if a key matching key exists.
|
noexcept |
Inserts a key.
When multi_t is false and a matching key already exists, returns a const pointer to the existing element without inserting. Otherwise inserts in sorted order and returns a const pointer to the new element.
|
noexcept |
|
noexcept |
| const key_t_ * hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::lower_bound | ( | const key_t_ & | key_ | ) | const |
Returns a const pointer to the first element whose key is not ordered before key.
Returns end if no such element exists.
|
inline |
Returns the capacity of the set.
| bool hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::operator< | ( | const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > & | x_ | ) | const |
Returns true if this set compares less than x lexicographically, using hxkey_equal and hxkey_less on keys.
|
noexcept |
Assigns the contents of x to this set.
Clears this set then copies all elements from x. Requires x.size() ≤ capacity().
|
noexcept |
Cross-capacity copy assignment.
Assigns the contents of x to this set. Requires x.size() ≤ capacity().
|
noexcept |
Move assigns from a temporary set using swap.
Requires hxallocator_dynamic_capacity.
| bool hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::operator== | ( | const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > & | x_ | ) | const |
Returns true if this set and x contain the same keys in the same order using hxkey_equal.
| const key_t_ * hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::operator[] | ( | hxsize_t | index_ | ) | const |
Returns a const pointer to the element at index.
Requires index < size().
| auto hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::or_else | ( | this self_t_ && | self_, |
| const key_t_ & | key_, | ||
| callable_t_ && | callable_ )->decltype(self_.end()) |
Returns a pointer to the first key matching key, or the result of calling callable when lookup fails.
| auto hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::or_else | ( | this self_t_ && | self_, |
| const key_t_ * | it_, | ||
| callable_t_ && | callable_ )->decltype(self_.end()) |
| void hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::reserve | ( | hxsize_t | cap_, |
| hxsystem_allocator_t | allocator_ = hxsystem_allocator_current, | ||
| hxalignment_t | alignment_ = hxalignment ) |
Allocates storage for cap keys.
When capacity is fixed, cap must equal capacity. Reallocation is not allowed.
|
inline |
Returns the number of elements in the set.
|
noexcept |
| const key_t_ * hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::upper_bound | ( | const key_t_ & | key_ | ) | const |
Returns a const pointer to the first element whose key is ordered after key.
Returns end if no such element exists.
| key_t_ hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::value_or | ( | this self_t_ && | self_, |
| const key_t_ & | key_, | ||
| args_t_ &&... | args_ ) |
Returns a copy of the first key matching key, or a key constructed from args when lookup fails.
| key_t_ hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::value_or | ( | this self_t_ && | self_, |
| const key_t_ * | it_, | ||
| args_t_ &&... | args_ ) |