|
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 (void) noexcept | |
| 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 |
| 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 |
| bool | empty (void) const |
| const key_t_ * | end (void) const |
| template<hxsize_t capacity_x_> | |
| bool | equal (const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| hxsize_t | erase (const key_t_ &key_) noexcept |
| const key_t_ * | erase (const key_t_ *pos_) noexcept |
| const key_t_ * | find (const key_t_ &key_) const |
| bool | full (void) const |
| const key_t_ * | insert (const key_t_ &key_) noexcept |
| const key_t_ * | insert (key_t_ &&key_) noexcept |
| template<hxsize_t capacity_x_> | |
| bool | less (const hxflat_set< key_t_, compare_t_, multi_t_, capacity_x_ > &x_) const |
| const key_t_ * | lower_bound (const key_t_ &key_) const |
| hxsize_t | max_size (void) const |
| 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 |
hxflat_set - A sorted associative container that stores keys in a single array.
Lookup is Θ(log n) via binary search. Insert and erase are Θ(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 - 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 |
Destructs the set and destroys all keys.
|
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.
|
inline |
Checks if the set contains no elements.
|
inline |
Returns a const pointer past the last element.
| bool hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::equal | ( | 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.
|
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 hxnull if not present.
When multi_t is true the first match is returned.
|
inline |
Returns true if the set has reached its capacity.
|
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 |
Move overload of insert.
| bool hxflat_set< key_t_, compare_t_, multi_t_, capacity_ >::less | ( | 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.
| 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.
|
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.
| 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().
| 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.