Pigweed
 
Loading...
Searching...
No Matches
pw::IntrusiveMultiMap< Key, T > Class Template Reference

#include <intrusive_multimap.h>

Classes

class  const_iterator
 
class  iterator
 

Public Types

using Item = typename Tree::Item
 
using Pair = typename Tree::Pair
 
using key_type = Key
 
using mapped_type = std::remove_cv_t< T >
 
using value_type = Item
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using key_compare = Compare
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

constexpr IntrusiveMultiMap ()
 Constructs an empty map of items.
 
template<typename Comparator >
constexpr IntrusiveMultiMap (Comparator &&compare)
 
template<typename Comparator , typename KeyRetriever >
constexpr IntrusiveMultiMap (Comparator &&compare, KeyRetriever &&get_key)
 
template<typename Iterator , typename... Functors>
 IntrusiveMultiMap (Iterator first, Iterator last, Functors &&... functors)
 
template<typename... Functors>
 IntrusiveMultiMap (std::initializer_list< T * > items, Functors &&... functors)
 
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
 
bool empty () const noexcept
 Returns whether the multimap has zero items or not.
 
size_t size () const
 Returns the number of items in the multimap.
 
constexpr size_t max_size () const noexcept
 
void clear ()
 
iterator insert (T &item)
 Adds the given item to the multimap.
 
iterator insert (iterator, T &item)
 
template<class Iterator >
void insert (Iterator first, Iterator last)
 
void insert (std::initializer_list< T * > ilist)
 
iterator erase (T &item)
 
iterator erase (iterator pos)
 
iterator erase (iterator first, iterator last)
 
size_t erase (const Key &key)
 
void swap (IntrusiveMultiMap< Key, T > &other)
 Exchanges this multimap's items with the other multimap's items.
 
template<typename MapType >
void merge (MapType &other)
 Splices items from the other map into this one.
 
size_t count (const Key &key) const
 Returns the number of items in the multimap with the given key.
 
iterator find (const Key &key)
 
const_iterator find (const Key &key) const
 
std::pair< iterator, iteratorequal_range (const Key &key)
 
std::pair< const_iterator, const_iteratorequal_range (const Key &key) const
 
iterator lower_bound (const Key &key)
 
const_iterator lower_bound (const Key &key) const
 
iterator upper_bound (const Key &key)
 
const_iterator upper_bound (const Key &key) const
 

Friends

template<typename , typename >
class IntrusiveMap
 

Detailed Description

template<typename Key, typename T>
class pw::IntrusiveMultiMap< Key, T >

A std::multimap<Key, T, Compare>-like class that uses intrusive items.

Since the map structure is stored in the items themselves, each item must outlive any map it is a part of and must be part of at most one map.

This map requires unique keys. Attempting to add an item with same key as an item already in the map will fail.

  • Since items are not allocated by this class, the following methods have no analogue:
    • std::multimap<T>::operator=
    • std::multimap<T>::get_allocator
    • std::multimap<T>::emplace
    • std::multimap<T>::emplace_hint
  • Methods corresponding to the following take initializer lists of pointer to items rather than the items themselves:
    • std::multimap<T>::(constructor)
    • std::multimap<T>::insert
  • There are no overloads corresponding to the following methods that take r-value references.:
    • std::multimap<T>::insert
    • std::multimap<T>::merge
  • Since modifying the map modifies the items themselves, methods corresponding to those below only take iterators and not const_iterators:
    • std::multimap<T>::insert
    • std::multimap<T>::erase
  • An additional overload of erase is provided that takes a direct reference to an item.
  • C++23 methods are not (yet) supported.
Template Parameters
KeyType to sort items on
TType of values stored in the map.

Member Typedef Documentation

◆ Item

template<typename Key , typename T >
using pw::IntrusiveMultiMap< Key, T >::Item = typename Tree::Item

IntrusiveMultiMap items must derive from either Item or Pair. Use Pair to automatically provide storage for a Key. Use Item when the derived type has a key() accessor method or when the map provides a custom GetKey function object.

Constructor & Destructor Documentation

◆ IntrusiveMultiMap() [1/4]

template<typename Key , typename T >
template<typename Comparator >
constexpr pw::IntrusiveMultiMap< Key, T >::IntrusiveMultiMap ( Comparator &&  compare)
inlineexplicitconstexpr

Constructs an empty map of items.

SFINAE is used to disambiguate between this constructor and the one that takes an initializer list.

Parameters
compareFunction with the signature bool(Key, Key) that is used to order items.
get_keyFunction with signature Key(const T&) that returns the value that items are sorted on.

◆ IntrusiveMultiMap() [2/4]

template<typename Key , typename T >
template<typename Comparator , typename KeyRetriever >
constexpr pw::IntrusiveMultiMap< Key, T >::IntrusiveMultiMap ( Comparator &&  compare,
KeyRetriever &&  get_key 
)
inlineconstexpr

Constructs an empty map of items.

Parameters
compareFunction with the signature bool(Key, Key) that is used to order items.
get_keyFunction with signature Key(const T&) that returns the value that items are sorted on.

◆ IntrusiveMultiMap() [3/4]

template<typename Key , typename T >
template<typename Iterator , typename... Functors>
pw::IntrusiveMultiMap< Key, T >::IntrusiveMultiMap ( Iterator  first,
Iterator  last,
Functors &&...  functors 
)
inline

Constructs an IntrusiveMultiMap from an iterator over Items.

The iterator may dereference as either Item& (e.g. from std::array<Item>) or Item* (e.g. from std::initializer_list<Item*>).

◆ IntrusiveMultiMap() [4/4]

template<typename Key , typename T >
template<typename... Functors>
pw::IntrusiveMultiMap< Key, T >::IntrusiveMultiMap ( std::initializer_list< T * >  items,
Functors &&...  functors 
)
inline

Constructs an IntrusiveMultiMap from a std::initializer_list of pointers to items.

Member Function Documentation

◆ clear()

template<typename Key , typename T >
void pw::IntrusiveMultiMap< Key, T >::clear ( )
inline

Removes all items from the multimap and leaves it empty.

The items themselves are not destructed.

◆ equal_range()

template<typename Key , typename T >
std::pair< iterator, iterator > pw::IntrusiveMultiMap< Key, T >::equal_range ( const Key &  key)
inline

Returns a pair of iterators where the first points to the item with the smallest key that is not less than the given key, and the second points to the item with the smallest key that is greater than the given key.

◆ erase()

template<typename Key , typename T >
iterator pw::IntrusiveMultiMap< Key, T >::erase ( T &  item)
inline

Removes an item from the multimap and returns an iterator to the item after the removed item.

The items themselves are not destructed.

◆ find()

template<typename Key , typename T >
iterator pw::IntrusiveMultiMap< Key, T >::find ( const Key &  key)
inline

Returns a pointer to an item with the given key, or null if the multimap does not contain such an item.

◆ lower_bound()

template<typename Key , typename T >
iterator pw::IntrusiveMultiMap< Key, T >::lower_bound ( const Key &  key)
inline

Returns an iterator to the item in the multimap with the smallest key that is greater than or equal to the given key, or end() if the multimap is empty.

◆ max_size()

template<typename Key , typename T >
constexpr size_t pw::IntrusiveMultiMap< Key, T >::max_size ( ) const
inlineconstexprnoexcept

Returns how many items can be added.

As an intrusive container, this is effectively unbounded.

◆ upper_bound()

template<typename Key , typename T >
iterator pw::IntrusiveMultiMap< Key, T >::upper_bound ( const Key &  key)
inline

Returns an iterator to the item in the multimap with the smallest key that is strictly greater than the given key, or end() if the multimap is empty.


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