|
|
| StackHashSet () |
| | Default constructor with empty stack storage.
|
| | StackHashSet (std::initializer_list< TKey > init) |
| | Construct set from initializer_list.
|
| template<typename InputIt> |
| | StackHashSet (InputIt first, InputIt last) |
| | Construct set from iterator range.
|
| bool | isEmpty () const noexcept |
| | Check if the set is empty.
|
| size_t | size () const noexcept |
| | Get the number of elements in the set.
|
| std::pair< const value_type *, bool > | insert (const TKey &key) |
| | Insert a key (copy semantics).
|
| std::pair< const value_type *, bool > | insert (TKey &&key) |
| | Insert a key (move semantics).
|
| template<typename... Args> |
| std::pair< const value_type *, bool > | emplace (Args &&... args) |
| | Emplace a key with in-place construction.
|
| size_t | erase (const TKey &key) |
| | Erase element by key.
|
| void | clear () noexcept |
| | Clear all elements from the set.
|
| std::optional< TKey > | extract (const TKey &key) |
| | Extract a key from the set without destroying it.
|
| void | merge (StackHashSet &other) |
| | Merge another StackHashSet into this one.
|
| void | merge (StackHashSet &&other) |
| | Merge another StackHashSet into this one (rvalue overload).
|
| const TKey * | find (const TKey &key) const noexcept |
| | Find key in the set (const pointer version).
|
| bool | contains (const TKey &key) const |
| | Check if a key exists in the set.
|
template<typename K>
requires requires( KeyEqual eq, const K& k, const TKey& t ) { eq( k, t ); } |
| bool | contains (const K &key) const |
| | Check if a key exists in the set (heterogeneous lookup).
|
| const TKey & | at (const TKey &key) const |
| | Access key in the set with bounds checking.
|
| template<typename Func> |
| void | forEach (Func &&func) |
| | Apply a function to each key.
|
| template<typename Func> |
| void | forEach (Func &&func) const |
| | Apply a function to each key (const version).
|
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
class nfx::containers::StackHashSet< TKey, N, KeyEqual >
Hash set with small buffer optimization for stack-allocated storage.
- Template Parameters
-
| TKey | Key type (supports heterogeneous lookup for compatible types) |
| N | Maximum stack capacity before heap allocation (default: 8) |
| KeyEqual | Key equality comparator (default: std::equal_to<> for transparent comparison) |
StackHashSet uses a hybrid storage strategy:
- Small capacity (≤N): Linear search in stack-allocated array (cache-friendly, zero heap allocations)
- Large capacity (>N): Automatic transition to FastHashSet (Robin Hood hashing on heap)
This is ideal for small sets (config flags, tags, local caches) where heap allocation overhead would dominate performance. The transition to heap is transparent and automatic.
Definition at line 66 of file StackHashSet.h.
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
template<typename K>
requires requires( KeyEqual eq, const K& k, const TKey& t ) { eq( k, t ); }
Check if a key exists in the set (heterogeneous lookup).
- Template Parameters
-
| K | Key type (supports heterogeneous lookup for compatible types) |
- Parameters
-
- Returns
- true if key exists, false otherwise
- Note
- This function is marked [[nodiscard]] - the return value should not be ignored
-
Enabled only if KeyEqual supports comparing K with TKey
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
Extract a key from the set without destroying it.
- Parameters
-
- Returns
- std::optional containing the extracted key if found, std::nullopt otherwise
Removes the element from the set and returns the key. If the key is not found, returns std::nullopt.
- Note
- This function is marked [[nodiscard]] - the return value should not be ignored
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
template<typename Func>
Apply a function to each key.
- Template Parameters
-
| Func | Function type with signature void(TKey&) or compatible |
- Parameters
-
| func | Function to apply to each element |
Iterates over all elements in unspecified order. For stack storage, iteration order matches insertion order (up to N elements). For heap storage, iteration order is unspecified (hash table order).
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
template<typename Func>
Apply a function to each key (const version).
- Template Parameters
-
| Func | Function type with signature void(const TKey&) or compatible |
- Parameters
-
| func | Function to apply to each element |
Iterates over all elements in unspecified order. For stack storage, iteration order matches insertion order (up to N elements). For heap storage, iteration order is unspecified (hash table order).
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
Insert a key (copy semantics).
- Parameters
-
- Returns
- Pair of pointer to element and bool indicating insertion success
If key already exists, returns pointer to existing element and false. Otherwise inserts new element and returns pointer with true. May trigger transition to heap storage.
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
Insert a key (move semantics).
- Parameters
-
| key | The key to insert (moved) |
- Returns
- Pair of pointer to element and bool indicating insertion success
If key already exists, returns pointer to existing element and false. Otherwise inserts new element and returns pointer with true. May trigger transition to heap storage.
template<typename TKey, size_t N = 8, typename KeyEqual = std::equal_to<>>
Merge another StackHashSet into this one.
- Parameters
-
| other | The set to merge from (elements are moved, not copied) |
Attempts to insert each element from other into this set. Elements that already exist in this set are left in other. After the operation, other contains only elements that were not inserted.