C/C++ API Reference
Loading...
Searching...
No Matches
pw::DynamicHashMap< Key, Value, Hash, Equal, SizeType > Class Template Reference

Overview

template<typename Key, typename Value, typename Hash = pw::Hash, typename Equal = pw::EqualTo, typename SizeType = uint16_t>
class pw::DynamicHashMap< Key, Value, Hash, Equal, SizeType >

Unordered associative container, similar to std::unordered_map, but optimized for embedded environments.

Key features of pw::DynamicHashMap:

  • Uses a pw::Allocator for all memory operations.
  • Provides the std::unordered_map API, but adds try_* versions of operations that crash on allocation failure.
  • Hybrid storage model:
    • Nodes: Stored in a dense DynamicPtrVector to enable efficient, linear iteration.
    • Buckets: Stored in a DynamicDeque for O(1) average lookup.
  • Unstable Iteration: Uses "swap-and-pop" erasure for efficiency. Erasing an element moves the last element of the map into the erased position, changing the iteration order.
  • Never allocates in the constructor.

Public Types

using key_type = Key
 
using mapped_type = Value
 
using value_type = KeyValueType
 
using size_type = SizeType
 
using difference_type = std::ptrdiff_t
 
using hasher = Hash
 
using key_equal = Equal
 
using allocator_type = Allocator
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using iterator = Iterator< false >
 
using const_iterator = Iterator< true >
 
using node_type = NodeType
 
using insert_return_type = std::pair< iterator, bool >
 

Public Member Functions

constexpr DynamicHashMap (Allocator &allocator, const Hash &hash=Hash(), const Equal &equal=Equal()) noexcept
 
 DynamicHashMap (const DynamicHashMap &)=delete
 
DynamicHashMapoperator= (const DynamicHashMap &)=delete
 
 DynamicHashMap (DynamicHashMap &&other) noexcept
 
DynamicHashMapoperator= (DynamicHashMap &&other) noexcept
 
allocator_typeget_allocator () const
 Returns the allocator used by this map.
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
bool empty () const
 
size_type size () const
 
size_type max_size () const
 
void clear ()
 
std::optional< insert_return_type > try_insert (const value_type &value)
 
std::optional< insert_return_type > try_insert (value_type &&)=delete
 
insert_return_type insert (const value_type &value)
 Inserts a value into the map. Crashes on allocation failure.
 
insert_return_type insert (value_type &&value)
 
template<typename InputIt , typename = containers::internal::EnableIfInputIterator<InputIt>>
void insert (InputIt first, InputIt last)
 
void insert (std::initializer_list< value_type > ilist)
 
template<typename K , typename... Args>
std::optional< std::pair< iterator, bool > > try_emplace (K &&key, Args &&... args)
 
template<typename K , typename... Args>
std::pair< iterator, bool > emplace (K &&key, Args &&... args)
 Constructs an element in-place. Crashes on allocation failure.
 
iterator erase (iterator pos)
 
iterator erase (const_iterator pos)
 
iterator erase (const_iterator first, const_iterator last)
 
template<typename K >
size_type erase (K &&key)
 
void swap (DynamicHashMap &other) noexcept
 Swaps the contents of two maps. No allocations occur.
 
void merge (DynamicHashMap &other)
 
void merge (DynamicHashMap &&other)
 
mapped_type & at (const key_type &key)
 
const mapped_type & at (const key_type &key) const
 
template<typename U = mapped_type, typename = std::enable_if_t<std::is_default_constructible_v<U>>>
mapped_type & operator[] (const key_type &key)
 
size_type count (const key_type &key) const
 Returns the number of elements with key key (0 or 1).
 
iterator find (const key_type &key)
 
const_iterator find (const key_type &key) const
 
bool contains (const key_type &key) const
 
std::pair< iterator, iterator > equal_range (const key_type &key)
 
std::pair< const_iterator, const_iterator > equal_range (const key_type &key) const
 
size_type load_factor_percent () const
 
size_type max_load_factor_percent () const
 
void max_load_factor_percent (size_type percent)
 
bool try_rehash (size_type count)
 
void rehash (size_type count)
 
bool try_reserve (size_type count)
 
void reserve (size_type count)
 

The documentation for this class was generated from the following file: