|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Sorted-array set (Aleph::FlatSet), a cache-friendly ordered set.
More...
#include <algorithm>#include <initializer_list>#include <iterator>#include <utility>#include <ah-errors.H>#include <ahFunction.H>#include <tpl_memArray.H>#include <tpl_sort_utils.H>Go to the source code of this file.
Classes | |
| class | Aleph::FlatSet< Key, Compare > |
| Ordered set stored as a sorted contiguous array. More... | |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
Sorted-array set (Aleph::FlatSet), a cache-friendly ordered set.
FlatSet<Key, Compare> keeps its keys sorted inside a single contiguous MemArray<Key>. Lookups are binary searches over contiguous memory (O(log n) with excellent cache behavior); insertions and removals shift elements (O(n)). It is the classic flat container trade-off, in the spirit of C++23 std::flat_set and boost::container::flat_set:
| Operation | FlatSet | DynSetTree (AVL/RB) |
|---|---|---|
| find / contains | O(log n), contiguous | O(log n), pointer chasing |
| insert / erase | O(n) shift | O(log n) |
| iteration | O(n), sequential memory | O(n), pointer chasing |
| memory per element | sizeof(Key) | sizeof(Key) + node overhead |
Prefer FlatSet for lookup- and iteration-heavy workloads whose modification phase is bulk or infrequent. Prefer DynSetTree when insertions and removals are frequent and interleaved with lookups.
std::flat_set when available: the standard adaptor has different reference/iterator semantics, and aliasing would make the container's exact behavior depend on -std. The detection macro ALEPH_HAS_STD_FLAT_MAP (see ah-cpp-compat.H) remains available for consumers that want the standard adaptor itself.Definition in file tpl_flat_set.H.