unordered_map< K, V, FIND_RETURNS_ITERATOR, SELECTOR > Class Template Reference

#include <maxonstd.h>

Inheritance diagram for unordered_map< K, V, FIND_RETURNS_ITERATOR, SELECTOR >:

Detailed Description

template<typename K, typename V, bool FIND_RETURNS_ITERATOR = true, typename SELECTOR = maxon::HashMapSelector<>>
class maxonstd::unordered_map< K, V, FIND_RETURNS_ITERATOR, SELECTOR >

maxonstd::unordered_map adapts a Maxon core HashMap to look like a std::unordered_map, so that it can be used as a substitute thereof. To change the settings of the underlying HashMap, you have to provide a HashMapSelector or BlockHashMapSelector via the SELECTOR template parameter.

FIND_RETURNS_ITERATOR controls the return type of the find functions. With the default of true, these functions return an iterator to be compatible with std::unordered_map. However, for an unordered map you almost never need the iterator capability of find's return value, because usually it makes no sense to proceed from there (an unordered map has unspecified order, neighboring elements have no relationship). You only need the iterator comparison function to detect if find was successful at all:

...
maxonstd::unordered_map<void*, String>::iterator it = map.find(ptr);
if (it != map.end())
{
// map contains entry for ptr
}
auto end()
Definition: maxonstd.h:77
typename COLLECTION::Iterator iterator
Definition: maxonstd.h:70
ConstFindResult find(const KeyType &key) const
Definition: maxonstd.h:400
Definition: maxonstd.h:488

You can use false for FIND_RETURNS_ITERATOR which makes the find functions return a more lightweight wrapper around HashMap::Entry without iterator capabilities. It can still be compared to an iterator, so the above code remains valid if you adapt it to the new type:

...
auto it = map.find(ptr); // return type is no longer an iterator
if (it != map.end()) // but it can be compared with an iterator
{
// map contains entry for ptr
}

But there's a conversion to Bool, so you can directly test for validity without the need of map.end():

...
auto it = map.find(ptr);
if (it) // the returned entry wrapper has a conversion to Bool to tell if an entry was found
{
// map contains entry for ptr
}

Note that maxonstd::unordered_map doesn't support std::unordered_map's additional template parameters for hash, comparison and allocator directly. However, you can achieve the same effect with corresponding template parameters of the HashMapSelector.

Template Parameters
KType of keys.
VType of values.
FIND_RETURNS_ITERATORBy default (true), the find functions return an iterator compatible with std library. With false, a more efficient wrapper around HashMap::Entry is returned without iterator capabilities.
SELECTORTo choose a HashMap with non-default template parameters, you have to provide a HashMapSelector with the desired configuration.
See also
HashMap, BlockHashMap

Public Types

using Super = unordered_map_base< typename SELECTOR::template Type< K, V >, FIND_RETURNS_ITERATOR >
 
using value_type = Entry
 
using FindResult = std::conditional_t< FIND_RETURNS_ITERATOR, iterator, EntryWrapper< false > >
 
using Super = container< MAP >
 
- Public Types inherited from unordered_map_base< SELECTOR::template Type< K, V >, true >
using Super = container< SELECTOR::template Type< K, V > >
 
using value_type = Entry
 
using FindResult = std::conditional_t< FIND_RETURNS_ITERATOR, iterator, EntryWrapper< false > >
 
using ConstFindResult = std::conditional_t< FIND_RETURNS_ITERATOR, const_iterator, EntryWrapper< true > >
 
- Public Types inherited from container< SELECTOR::template Type< K, V > >
using iterator = typename COLLECTION::Iterator
 
using const_iterator = typename COLLECTION::ConstIterator
 
using reverse_iterator = maxon::ReverseIterator< iterator >
 
using const_reverse_iterator = maxon::ReverseIterator< const_iterator >
 

Public Member Functions

std::pair< FindResult, bool > insert (const std::pair< const K, V > &value)
 
std::pair< FindResult, bool > insert (std::pair< const K, V > &&value)
 
template<typename PAIR >
std::pair< FindResult, bool > insert (PAIR &&value)
 
V & operator[] (const K &key)
 
- Public Member Functions inherited from unordered_map_base< SELECTOR::template Type< K, V >, true >
ConstFindResult find (const KeyType &key) const
 
FindResult find (const KeyType &key)
 
iterator erase (const iterator &it)
 
void erase (const EntryWrapper< false > &e)
 
- Public Member Functions inherited from container< SELECTOR::template Type< K, V > >
 container ()=default
 
 container (container &&)=default
 
 container (const container &src)
 
container & operator= (container &&)=default
 
container & operator= (const container &src)
 
maxon::Result< void > CopyFrom (const container &)=delete
 
auto begin ()
 
auto begin () const
 
auto end ()
 
auto end () const
 
auto cbegin () const
 
auto cend () const
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const
 
const_reverse_iterator rcbegin () const
 
const_reverse_iterator rcend () const
 
void clear ()
 
bool empty () const
 
std::size_t size () const
 

Private Member Functions

template<typename PAIR >
std::pair< FindResult, bool > insert_pair (PAIR &&value)
 

Additional Inherited Members

- Protected Member Functions inherited from unordered_map_base< SELECTOR::template Type< K, V >, true >
MAXON_ATTRIBUTE_FORCE_INLINE FindResult ToFindResult (Entry *e)
 
MAXON_ATTRIBUTE_FORCE_INLINE ConstFindResult ToFindResult (const Entry *e) const
 

Member Typedef Documentation

◆ Super [1/2]

using Super = unordered_map_base<typename SELECTOR::template Type<K, V>, FIND_RETURNS_ITERATOR>

◆ value_type

using value_type = Entry

◆ FindResult

using FindResult = std::conditional_t<FIND_RETURNS_ITERATOR, iterator, EntryWrapper<false> >

◆ Super [2/2]

using Super = container<MAP>

Member Function Documentation

◆ insert() [1/3]

std::pair<FindResult, bool> insert ( const std::pair< const K, V > &  value)

◆ insert() [2/3]

std::pair<FindResult, bool> insert ( std::pair< const K, V > &&  value)

◆ insert() [3/3]

std::pair<FindResult, bool> insert ( PAIR &&  value)

◆ operator[]()

V& operator[] ( const K &  key)

◆ insert_pair()

std::pair<FindResult, bool> insert_pair ( PAIR &&  value)
private