C/C++ API Reference
Loading...
Searching...
No Matches
pw::DynamicMap< Key, Value > Class Template Reference

Overview

template<typename Key, typename Value>
class pw::DynamicMap< Key, Value >

Dynamic ordered map, similar to std::map, but optimized for embedded.

Key features of pw::DynamicMap.

  • Uses a pw::Allocator for memory operations for each node.
  • Provides a std::map-like API, but adds try_* versions of operations that return std::nullopt on allocation failure.
  • Never allocates in the constructor. constexpr constructible.
  • Leverages pw::IntrusiveMap internally to manage the balanced tree structure without additional per-node overhead beyond the user data and tree pointers.

Public Types

using key_type = Key
 
using mapped_type = Value
 
using value_type = std::pair< const Key, Value >
 
using size_type = typename Map::size_type
 
using difference_type = typename Map::difference_type
 
using key_compare = typename Map::key_compare
 
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 reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using insert_return_type = std::pair< iterator, bool >
 

Public Member Functions

constexpr DynamicMap (Allocator &allocator) noexcept
 
 DynamicMap (const DynamicMap &)=delete
 
DynamicMapoperator= (const DynamicMap &)=delete
 
 DynamicMap (DynamicMap &&other) noexcept
 
DynamicMapoperator= (DynamicMap &&other) noexcept
 
constexpr allocator_typeget_allocator () const
 Returns the allocator used by this map.
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
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)
 
bool empty () const
 
size_type size () const
 
constexpr size_type max_size () const noexcept
 
void clear ()
 Removes all elements from the map and deallocates each node.
 
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)
 Inserts a range of elements. Crashes on allocation failure.
 
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)
 Removes the element at pos and deallocates the node.
 
iterator erase (const_iterator pos)
 
iterator erase (iterator first, iterator last)
 Removes elements in the range [first, last).
 
template<typename K >
size_type erase (K &&key)
 
void swap (DynamicMap &other)
 Swaps the contents and allocators of two maps. No allocations occur.
 
void merge (DynamicMap &other)
 
void merge (DynamicMap &&other)
 
size_type count (const key_type &key)
 
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
 
iterator lower_bound (const key_type &key)
 
const_iterator lower_bound (const key_type &key) const
 
iterator upper_bound (const key_type &key)
 
const_iterator upper_bound (const key_type &key) const
 

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