RADLib
RADical C++ application framework
RADData::RADFlatHashMap< K, V, Hash, Eq > Class Template Reference

Open-addressed flat hash map optimized for cache-local lookups. More...

#include <RADDataStructures.h>

Classes

class  const_iterator
 Const forward iterator over occupied map entries. More...
 
class  iterator
 Forward iterator over occupied map entries. More...
 

Public Types

using value_type = std::pair< K, V >
 Stored key/value pair type. More...
 

Public Member Functions

 RADFlatHashMap ()
 Creates an empty map with default capacity. More...
 
 RADFlatHashMap (size_t capacity)
 Creates an empty map with at least capacity slots. More...
 
 RADFlatHashMap (const RADFlatHashMap &other)
 Copies another map. More...
 
RADFlatHashMapoperator= (const RADFlatHashMap &other)
 Replaces this map with a copy of other. More...
 
 RADFlatHashMap (RADFlatHashMap &&other) noexcept
 Moves another map without rehashing. More...
 
RADFlatHashMapoperator= (RADFlatHashMap &&other) noexcept
 Replaces this map by taking other's storage. More...
 
 ~RADFlatHashMap ()
 Destroys entries and releases storage. More...
 
iterator begin () noexcept
 Returns iterator to first occupied entry. More...
 
iterator end () noexcept
 Returns iterator one past the entry table. More...
 
const_iterator begin () const noexcept
 Returns const iterator to first occupied entry. More...
 
const_iterator end () const noexcept
 Returns const iterator one past the entry table. More...
 
bool empty () const noexcept
 Returns true when the map contains no entries. More...
 
size_t size () const noexcept
 Returns number of occupied entries. More...
 
size_t capacity () const noexcept
 Returns current hash table capacity. More...
 
void clear () noexcept
 Removes all entries while keeping table storage. More...
 
bool contains (const K &key) const
 Returns true when key exists. More...
 
V * find (const K &key)
 Returns pointer to mapped value for key, or nullptr when absent. More...
 
const V * find (const K &key) const
 Returns const pointer to mapped value for key, or nullptr when absent. More...
 
std::pair< iterator, bool > insert (const K &key, const V &value)
 Inserts or replaces key with value. More...
 
template<typename KeyArg , typename ValueArg >
std::pair< iterator, bool > emplace (KeyArg &&key, ValueArg &&value)
 Inserts or replaces key/value with forwarding support. More...
 
V & operator[] (const K &key)
 Returns mapped value for key, inserting a default value if absent. More...
 
bool erase (const K &key)
 Erases key and returns true when an entry was removed. More...
 
void reserve (size_t desired)
 Reserves enough capacity for desired entries. More...
 

Detailed Description

template<typename K, typename V, typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
class RADData::RADFlatHashMap< K, V, Hash, Eq >

Open-addressed flat hash map optimized for cache-local lookups.

Member Typedef Documentation

◆ value_type

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
using RADData::RADFlatHashMap< K, V, Hash, Eq >::value_type = std::pair<K, V>

Stored key/value pair type.

Constructor & Destructor Documentation

◆ RADFlatHashMap() [1/4]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADData::RADFlatHashMap< K, V, Hash, Eq >::RADFlatHashMap ( )
inline

Creates an empty map with default capacity.

◆ RADFlatHashMap() [2/4]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADData::RADFlatHashMap< K, V, Hash, Eq >::RADFlatHashMap ( size_t  capacity)
inlineexplicit

Creates an empty map with at least capacity slots.

◆ RADFlatHashMap() [3/4]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADData::RADFlatHashMap< K, V, Hash, Eq >::RADFlatHashMap ( const RADFlatHashMap< K, V, Hash, Eq > &  other)
inline

Copies another map.

◆ RADFlatHashMap() [4/4]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADData::RADFlatHashMap< K, V, Hash, Eq >::RADFlatHashMap ( RADFlatHashMap< K, V, Hash, Eq > &&  other)
inlinenoexcept

Moves another map without rehashing.

◆ ~RADFlatHashMap()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADData::RADFlatHashMap< K, V, Hash, Eq >::~RADFlatHashMap ( )
inline

Destroys entries and releases storage.

Member Function Documentation

◆ begin() [1/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
const_iterator RADData::RADFlatHashMap< K, V, Hash, Eq >::begin ( ) const
inlinenoexcept

Returns const iterator to first occupied entry.

◆ begin() [2/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
iterator RADData::RADFlatHashMap< K, V, Hash, Eq >::begin ( )
inlinenoexcept

Returns iterator to first occupied entry.

◆ capacity()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
size_t RADData::RADFlatHashMap< K, V, Hash, Eq >::capacity ( ) const
inlinenoexcept

Returns current hash table capacity.

◆ clear()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
void RADData::RADFlatHashMap< K, V, Hash, Eq >::clear ( )
inlinenoexcept

Removes all entries while keeping table storage.

◆ contains()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
bool RADData::RADFlatHashMap< K, V, Hash, Eq >::contains ( const K &  key) const
inline

Returns true when key exists.

◆ emplace()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
template<typename KeyArg , typename ValueArg >
std::pair<iterator, bool> RADData::RADFlatHashMap< K, V, Hash, Eq >::emplace ( KeyArg &&  key,
ValueArg &&  value 
)
inline

Inserts or replaces key/value with forwarding support.

◆ empty()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
bool RADData::RADFlatHashMap< K, V, Hash, Eq >::empty ( ) const
inlinenoexcept

Returns true when the map contains no entries.

◆ end() [1/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
const_iterator RADData::RADFlatHashMap< K, V, Hash, Eq >::end ( ) const
inlinenoexcept

Returns const iterator one past the entry table.

◆ end() [2/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
iterator RADData::RADFlatHashMap< K, V, Hash, Eq >::end ( )
inlinenoexcept

Returns iterator one past the entry table.

◆ erase()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
bool RADData::RADFlatHashMap< K, V, Hash, Eq >::erase ( const K &  key)
inline

Erases key and returns true when an entry was removed.

◆ find() [1/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
V* RADData::RADFlatHashMap< K, V, Hash, Eq >::find ( const K &  key)
inline

Returns pointer to mapped value for key, or nullptr when absent.

◆ find() [2/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
const V* RADData::RADFlatHashMap< K, V, Hash, Eq >::find ( const K &  key) const
inline

Returns const pointer to mapped value for key, or nullptr when absent.

◆ insert()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
std::pair<iterator, bool> RADData::RADFlatHashMap< K, V, Hash, Eq >::insert ( const K &  key,
const V &  value 
)
inline

Inserts or replaces key with value.

◆ operator=() [1/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADFlatHashMap& RADData::RADFlatHashMap< K, V, Hash, Eq >::operator= ( const RADFlatHashMap< K, V, Hash, Eq > &  other)
inline

Replaces this map with a copy of other.

◆ operator=() [2/2]

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
RADFlatHashMap& RADData::RADFlatHashMap< K, V, Hash, Eq >::operator= ( RADFlatHashMap< K, V, Hash, Eq > &&  other)
inlinenoexcept

Replaces this map by taking other's storage.

◆ operator[]()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
V& RADData::RADFlatHashMap< K, V, Hash, Eq >::operator[] ( const K &  key)
inline

Returns mapped value for key, inserting a default value if absent.

◆ reserve()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
void RADData::RADFlatHashMap< K, V, Hash, Eq >::reserve ( size_t  desired)
inline

Reserves enough capacity for desired entries.

◆ size()

template<typename K , typename V , typename Hash = std::hash<K>, typename Eq = std::equal_to<K>>
size_t RADData::RADFlatHashMap< K, V, Hash, Eq >::size ( ) const
inlinenoexcept

Returns number of occupied entries.


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