39#include <initializer_list>
44namespace nfx::containers
63 template <
typename TKey,
65 typename KeyEqual = std::equal_to<>>
109 template <
typename InputIt>
121 [[nodiscard]]
inline bool isEmpty() const noexcept;
128 [[nodiscard]] inline
size_t size() const noexcept;
135 [[nodiscard]] static constexpr
size_t stackCapacity() noexcept {
return N; }
149 inline std::pair<const value_type*, bool>
insert(
const TKey& key );
159 inline std::pair<const value_type*, bool>
insert( TKey&& key );
167 template <
typename... Args>
168 inline std::pair<const value_type*, bool>
emplace( Args&&... args );
175 inline size_t erase(
const TKey& key );
191 [[nodiscard]] inline std::optional<TKey>
extract( const TKey& key );
219 [[nodiscard]] inline const TKey*
find( const TKey& key ) const noexcept;
227 [[nodiscard]] inline
bool contains( const TKey& key ) const;
237 template <typename K>
238 [[nodiscard]] inline
bool contains( const K& key ) const
239 requires requires( KeyEqual eq, const K& k, const TKey& t ) { eq( k, t ); };
248 inline const TKey&
at(
const TKey& key )
const;
262 template <
typename Func>
273 template <
typename Func>
286 std::optional<TKey> data;
292 std::array<StackEntry, N> m_stack;
302 std::unique_ptr<FastHashSet<TKey>> m_heap;
308 [[nodiscard]]
inline bool isOnStack() const noexcept;
314 inline
void transitionToHeap();
318#include "nfx/detail/containers/StackHashSet.inl"
Hash set with Robin Hood hashing and heterogeneous lookup.
size_t size() const noexcept
Get the number of elements in the set.
size_t erase(const TKey &key)
Erase element by key.
std::pair< const value_type *, bool > emplace(Args &&... args)
Emplace a key with in-place construction.
void forEach(Func &&func) const
Apply a function to each key (const version).
bool contains(const TKey &key) const
Check if a key exists in the set.
const TKey & at(const TKey &key) const
Access key in the set with bounds checking.
TKey value_type
Type alias for value type (same as key_type for sets).
KeyEqual key_equal
Type alias for key equality comparator.
std::ptrdiff_t difference_type
Type alias for difference type.
size_t size_type
Type alias for size type.
TKey key_type
Type alias for key type.
StackHashSet()
Default constructor with empty stack storage.
void forEach(Func &&func)
Apply a function to each key.
bool isEmpty() const noexcept
Check if the set is empty.
void merge(StackHashSet &other)
Merge another StackHashSet into this one.
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).
static constexpr size_t stackCapacity() noexcept
Get the maximum stack capacity before heap allocation.
std::optional< TKey > extract(const TKey &key)
Extract a key from the set without destroying it.
StackHashSet(InputIt first, InputIt last)
Construct set from iterator range.
StackHashSet(std::initializer_list< TKey > init)
Construct set from initializer_list.
const TKey * find(const TKey &key) const noexcept
Find key in the set (const pointer version).
void clear() noexcept
Clear all elements from the set.