unordered_set< T, FIND_RETURNS_ITERATOR, SELECTOR > Class Template Reference

#include <maxonstd.h>

Inheritance diagram for unordered_set< T, FIND_RETURNS_ITERATOR, SELECTOR >:

Detailed Description

template<typename T, bool FIND_RETURNS_ITERATOR = true, typename SELECTOR = maxon::HashSetSelector<>>
class maxonstd::unordered_set< T, FIND_RETURNS_ITERATOR, SELECTOR >

maxonstd::unordered_set adapts a Maxon core HashSet to look like a std::unordered_set, so that it can be used as a substitute thereof. To change the settings of the underlying HashSet, you have to provide a HashSetSelector or BlockHashSetSelector 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_set. However, for an unordered set you almost never need the iterator capability of find's return value, because usually it makes no sense to proceed from there (an unordered set 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_set<String>::iterator it = set.find(s);
if (it != set.end())
{
// set contains entry for s
}
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:578

You can use false for FIND_RETURNS_ITERATOR which makes the find functions return a more lightweight wrapper around HashSet::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 = set.find(s); // return type is no longer an iterator
if (it != set.end()) // but it can be compared with an iterator
{
// set contains entry for s
}

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

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

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

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

Public Types

using Super = unordered_map_base< typename SELECTOR::template Type< T >, FIND_RETURNS_ITERATOR >
 
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< T >, true >
using Super = container< SELECTOR::template Type< T > >
 
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< T > >
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 T &value)
 
std::pair< FindResult, bool > insert (T &&value)
 
size_t erase (const T &key)
 
iterator erase (const iterator &it)
 
void erase (const EntryWrapper< false > &e)
 
- Public Member Functions inherited from unordered_map_base< SELECTOR::template Type< T >, 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< T > >
 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
 

Additional Inherited Members

- Protected Member Functions inherited from unordered_map_base< SELECTOR::template Type< T >, 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<T>, FIND_RETURNS_ITERATOR>

◆ FindResult

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

◆ Super [2/2]

using Super = container<MAP>

Member Function Documentation

◆ insert() [1/2]

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

◆ insert() [2/2]

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

◆ erase() [1/3]

size_t erase ( const T &  key)

◆ erase() [2/3]

iterator erase

◆ erase() [3/3]

void erase