37#include <nfx/Hashing.h>
49namespace nfx::containers
79 template <
typename TKey,
81 hashing::Hash32or64 HashType = uint32_t,
82 HashType Seed = (
sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ),
83 typename Hasher = hashing::Hasher<HashType, Seed>,
84 typename KeyEqual = std::equal_to<>>
198 [[nodiscard]] inline
bool operator==( const
PerfectHashMap& other ) const noexcept;
205 [[nodiscard]] inline
bool operator!=( const
PerfectHashMap& other ) const noexcept;
220 template <typename K>
221 inline const TValue&
at( const K& key ) const;
236 template <typename K>
237 [[nodiscard]] inline
bool contains( const K& key ) const noexcept;
246 template <typename K>
247 [[nodiscard]] inline const TValue*
find( const K& key ) const noexcept;
272 [[nodiscard]] inline
bool isEmpty() const noexcept;
358 inline Iterator(
const std::vector<std::optional<std::pair<TKey, TValue>>>* table,
size_t index );
415 inline void skipEmpty();
421 const std::vector<std::optional<std::pair<TKey, TValue>>>* m_table;
426 size_t m_itemCount = 0;
427 std::vector<std::optional<std::pair<TKey, TValue>>> m_table;
428 std::vector<seed_type> m_seeds;
434#include "nfx/detail/containers/PerfectHashMap.inl"
hasher hash_function() const
Get the hash function object.
const TValue * find(const K &key) const noexcept
Fast lookup with heterogeneous key types (C++ idiom: pointer return).
std::make_signed_t< hash_type > seed_type
Type alias for signed seed type (used internally for displacement seeds).
ConstIterator cbegin() const noexcept
Get const iterator to beginning of occupied slots (explicit const).
key_equal key_eq() const
Get the key equality comparison function object.
PerfectHashMap()=default
Default constructor creates an empty map.
size_type count() const noexcept
Get the number of elements in the map.
bool contains(const K &key) const noexcept
Check if a key exists in the map.
Iterator ConstIterator
Alias for const iterator.
Iterator end() const noexcept
Get iterator to end (past last occupied slot).
HashType hash_type
Type alias for hash type (uint32_t or uint64_t).
PerfectHashMap(std::vector< std::pair< TKey, TValue > > &&items)
Constructs a perfect hash map from a vector of key-value pairs.
Hasher hasher
Type alias for hasher type.
Iterator iterator
Primary iterator class.
KeyEqual key_equal
Type alias for key equality comparator.
size_t size_type
Type alias for size type.
std::pair< TKey, TValue > value_type
Type alias for key-value pair type.
PerfectHashMap(PerfectHashMap &&) noexcept=default
Move constructor.
TValue mapped_type
Type alias for mapped value type.
TKey key_type
Type alias for key type.
bool isEmpty() const noexcept
Check if the map is empty.
size_type size() const noexcept
Get the total size of the hash table.
PerfectHashMap(const PerfectHashMap &)=default
Copy constructor.
std::ptrdiff_t difference_type
Type alias for difference type.
ConstIterator cend() const noexcept
Get const iterator to end (explicit const).
const TValue & at(const K &key) const
Access element with bounds checking.
Iterator begin() const noexcept
Get iterator to beginning of occupied slots.
Iterator const_iterator
Type alias for const iterator (same as iterator since map is immutable).
Const forward iterator for PerfectHashMap.
pointer operator->() const
Arrow operator to access key-value pair members.
Iterator & operator++()
Pre-increment operator to advance to next occupied slot.
std::pair< TKey, TValue > value_type
STL iterator value type (key-value pair).
Iterator(const std::vector< std::optional< std::pair< TKey, TValue > > > *table, size_t index)
Construct iterator from table pointers and index.
bool operator==(const Iterator &other) const
Equality comparison operator.
bool operator!=(const Iterator &other) const
Inequality comparison operator.
Iterator operator++(int)
Post-increment operator to advance to next occupied slot.
std::forward_iterator_tag iterator_category
STL iterator category (forward iterator).
const value_type * pointer
STL iterator pointer type (const).
std::ptrdiff_t difference_type
STL iterator difference type.
const value_type & reference
STL iterator reference type (const).
reference operator*() const
Dereference operator to access key-value pair.