emilib
Classes | Public Types | Public Member Functions | List of all members
emilib::HashMap< KeyT, ValueT, HashT, EqT > Class Template Reference

A cache-friendly hash table with open addressing, linear probing and power-of-two capacity. More...

#include <hash_map.hpp>

Classes

class  const_iterator
 
class  iterator
 

Public Types

using size_type = size_t
 
using value_type = PairT
 
using reference = PairT &
 
using const_reference = const PairT &
 

Public Member Functions

 HashMap (const HashMap &other)
 
 HashMap (HashMap &&other)
 
HashMapoperator= (const HashMap &other)
 
void operator= (HashMap &&other)
 
void swap (HashMap &other)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
size_t size () const
 
bool empty () const
 
iterator find (const KeyT &key)
 
const_iterator find (const KeyT &key) const
 
bool contains (const KeyT &k) const
 
size_t count (const KeyT &k) const
 
ValueT * try_get (const KeyT &k)
 Returns the matching ValueT or nullptr if k isn't found.
 
const ValueT * try_get (const KeyT &k) const
 Const version of the above.
 
const ValueT get_or_return_default (const KeyT &k) const
 Convenience function.
 
std::pair< iterator, bool > insert (const KeyT &key, const ValueT &value)
 
std::pair< iterator, bool > insert (const std::pair< KeyT, ValueT > &p)
 
void insert (const_iterator begin, const_iterator end)
 
void insert_unique (KeyT &&key, ValueT &&value)
 Same as above, but contains(key) MUST be false.
 
void insert_unique (std::pair< KeyT, ValueT > &&p)
 
ValueT set_get (const KeyT &key, const ValueT &new_value)
 Return the old value or ValueT() if it didn't exist.
 
ValueT & operator[] (const KeyT &key)
 Like std::map<KeyT,ValueT>::operator[].
 
bool erase (const KeyT &key)
 
iterator erase (iterator it)
 
void clear ()
 Remove all elements, keeping full capacity.
 
void reserve (size_t num_elems)
 Make room for this many elements.
 

Detailed Description

template<typename KeyT, typename ValueT, typename HashT = std::hash<KeyT>, typename EqT = HashMapEqualTo<KeyT>>
class emilib::HashMap< KeyT, ValueT, HashT, EqT >

A cache-friendly hash table with open addressing, linear probing and power-of-two capacity.

Member Function Documentation

◆ erase() [1/2]

template<typename KeyT , typename ValueT , typename HashT = std::hash<KeyT>, typename EqT = HashMapEqualTo<KeyT>>
bool emilib::HashMap< KeyT, ValueT, HashT, EqT >::erase ( const KeyT &  key)
inline

Erase an element from the hash table. return false if element was not found

◆ erase() [2/2]

template<typename KeyT , typename ValueT , typename HashT = std::hash<KeyT>, typename EqT = HashMapEqualTo<KeyT>>
iterator emilib::HashMap< KeyT, ValueT, HashT, EqT >::erase ( iterator  it)
inline

Erase an element using an iterator. Returns an iterator to the next element (or end()).

◆ insert()

template<typename KeyT , typename ValueT , typename HashT = std::hash<KeyT>, typename EqT = HashMapEqualTo<KeyT>>
std::pair<iterator, bool> emilib::HashMap< KeyT, ValueT, HashT, EqT >::insert ( const KeyT &  key,
const ValueT &  value 
)
inline

Returns a pair consisting of an iterator to the inserted element (or to the element that prevented the insertion) and a bool denoting whether the insertion took place.


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