pstore2
Classes | Public Types | Public Member Functions | List of all members
pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual > Class Template Referencefinal

A Hash array mapped trie index type for the pstore. More...

#include <hamt_map.hpp>

Inheritance diagram for pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >:
Inheritance graph
[legend]
Collaboration diagram for pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >:
Collaboration graph
[legend]

Classes

class  iterator_base
 Inner class that describes a const_iterator and 'regular' iterator. More...
 

Public Types

using key_equal = KeyEqual
 
using key_type = KeyType
 
using mapped_type = ValueType
 
using value_type = std::pair< KeyType const, ValueType >
 
using iterator = iterator_base< false >
 
using const_iterator = iterator_base< true >
 

Public Member Functions

 hamt_map (database const &db, typed_address< header_block > pos=typed_address< header_block >::null(), Hash const &hash=Hash(), KeyEqual const &equal=KeyEqual())
 An associative container that contains key-value pairs with unique keys. More...
 
 hamt_map (hamt_map const &)=delete
 
 hamt_map (hamt_map &&) noexcept=delete
 
hamt_mapoperator= (hamt_map const &)=delete
 
hamt_mapoperator= (hamt_map &&) noexcept=delete
 
typed_address< header_blockflush (transaction_base &transaction, unsigned generation)
 Flush any modified index nodes to the store. More...
 
template<typename OtherValueType >
auto insert_or_upsert (transaction_base &transaction, OtherValueType const &value, bool is_upsert) -> std::pair< iterator, bool >
 
template<typename OtherKeyType , typename >
auto find (database const &db, OtherKeyType const &key) const -> const_iterator
 
Iterators
range< database, hamt_map, iteratormake_range (database &db)
 
range< database const, hamt_map const, const_iteratormake_range (database const &db) const
 
iterator begin (database &db)
 Returns an iterator to the beginning of the container.
 
const_iterator begin (database const &db) const
 
const_iterator cbegin (database const &db) const
 
iterator end (database &db)
 Returns an iterator to the end of the container.
 
const_iterator end (database const &db) const
 
const_iterator cend (database const &db) const
 
Capacity
bool empty () const noexcept
 Checks whether the container is empty.
 
std::size_t size () const noexcept
 Returns the number of elements.
 
Modifiers
template<typename OtherKeyType , typename OtherValueType , typename = typename std::enable_if< pair_types_compatible<OtherKeyType, OtherValueType>::value>::type>
auto insert (transaction_base &transaction, std::pair< OtherKeyType, OtherValueType > const &value) -> std::pair< iterator, bool >
 Inserts an element into the hamt_map if the hamt_map doesn't already contain an element with an equivalent key. More...
 
template<typename OtherKeyType , typename OtherValueType , typename = typename std::enable_if< pair_types_compatible<OtherKeyType, OtherValueType>::value>::type>
auto insert_or_assign (transaction_base &transaction, std::pair< OtherKeyType, OtherValueType > const &value) -> std::pair< iterator, bool >
 If a key equivalent to value first already exists in the container, assigns value second to the mapped type. More...
 
template<typename OtherKeyType , typename OtherValueType , typename = typename std::enable_if< pair_types_compatible<OtherKeyType, OtherValueType>::value>::type>
auto insert_or_assign (transaction_base &transaction, OtherKeyType const &key, OtherValueType const &value) -> std::pair< iterator, bool >
 If a key equivalent to key already exists in the container, assigns value to the mapped type. More...
 
Lookup
template<typename OtherKeyType , typename = typename std::enable_if< serialize::is_compatible<OtherKeyType, KeyType>::value>::type>
const_iterator find (database const &db, OtherKeyType const &key) const
 Finds an element with key equivalent to key. More...
 
template<typename OtherKeyType , typename = typename std::enable_if< serialize::is_compatible<OtherKeyType, KeyType>::value>::type>
bool contains (database const &db, OtherKeyType const &key) const
 Checks if there is an element with key equivalent to key in the container. More...
 
Accessors

Provide access to index internals.

value_type load_leaf_node (database const &db, address addr) const
 Read a leaf node from a store.
 
index_pointer root () const noexcept
 Returns the index root pointer.
 

Detailed Description

template<typename KeyType, typename ValueType, typename Hash, typename KeyEqual>
class pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >

A Hash array mapped trie index type for the pstore.

Template Parameters
KeyTypeThe map key type.
ValueTypeThe map value type.
HashA function which produces the hash of a supplied key. The signature must be compatible with: index::details::hash_type(KeyType)
KeyEqualA function used to compare keys for equality. The signature must be compatible with: bool(KeyType, KeyType)

Constructor & Destructor Documentation

◆ hamt_map()

template<typename KeyType , typename ValueType , typename Hash, typename KeyEqual>
pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::hamt_map ( database const &  db,
typed_address< header_block pos = typed_address<header_block>::null (),
Hash const &  hash = Hash (),
KeyEqual const &  equal = KeyEqual () 
)
explicit

An associative container that contains key-value pairs with unique keys.

Parameters
dbA database to which the index belongs.
posThe index root address.
hashA function that yields a hash from the key value.
equalA function used to compare keys for equality.

Member Function Documentation

◆ contains()

template<typename KeyType, typename ValueType, typename Hash, typename KeyEqual>
template<typename OtherKeyType , typename = typename std::enable_if< serialize::is_compatible<OtherKeyType, KeyType>::value>::type>
bool pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::contains ( database const &  db,
OtherKeyType const &  key 
) const
inline

Checks if there is an element with key equivalent to key in the container.

Template Parameters
OtherKeyTypeA type whose serialized representation is compatible with KeyType.
Parameters
dbThe database to which the index belongs.
keyThe key value of the element to be check.
Returns
True if the element is present in the container, false otherwise.

◆ find()

template<typename KeyType, typename ValueType, typename Hash, typename KeyEqual>
template<typename OtherKeyType , typename = typename std::enable_if< serialize::is_compatible<OtherKeyType, KeyType>::value>::type>
const_iterator pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::find ( database const &  db,
OtherKeyType const &  key 
) const

Finds an element with key equivalent to key.

Template Parameters
OtherKeyTypeA type whose serialized representation is compatible with KeyType.
Parameters
dbThe database to which the index belongs.
keyThe key value of the element to be found.
Returns
Iterator to an element with key equivalent to key. If not such element is found, past-the end iterator it returned.

◆ flush()

template<typename KeyType , typename ValueType , typename Hash , typename KeyEqual >
typed_address< header_block > pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::flush ( transaction_base transaction,
unsigned  generation 
)

Flush any modified index nodes to the store.

Parameters
transactionThe transaction to which the map will be written.
generationThe generation number to which the map will be written.
Returns
The address of the index root node.

◆ insert()

template<typename KeyType , typename ValueType , typename Hash , typename KeyEqual >
template<typename OtherKeyType , typename OtherValueType , typename >
auto pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::insert ( transaction_base transaction,
std::pair< OtherKeyType, OtherValueType > const &  value 
) -> std::pair<iterator, bool>

Inserts an element into the hamt_map if the hamt_map doesn't already contain an element with an equivalent key.

If insertion occurs, all iterators are invalidated.

Template Parameters
OtherKeyTypeA type whose serialized representation is compatible with KeyType.
OtherValueTypeA type whose serialized representation is compatible with ValueType.
Parameters
transactionThe transaction to which the new key-value pair will be appended.
valueThe key-value pair to be inserted.
Returns
The bool component is true if the insertion took place and false if the assignment took place. The iterator component points at the exiting or new element.

◆ insert_or_assign() [1/2]

template<typename KeyType , typename ValueType , typename Hash , typename KeyEqual >
template<typename OtherKeyType , typename OtherValueType , typename >
auto pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::insert_or_assign ( transaction_base transaction,
std::pair< OtherKeyType, OtherValueType > const &  value 
) -> std::pair<iterator, bool>

If a key equivalent to value first already exists in the container, assigns value second to the mapped type.

If the key does not exist, inserts the new value as if by insert(). If insertion occurs, all iterators are invalidated.

Template Parameters
OtherKeyTypeA type whose serialized representation is compatible with KeyType.
OtherValueTypeA type whose serialized representation is compatible with ValueType.
Parameters
transactionThe transaction to which new data will be appended.
valueThe key-value pair to be inserted or updated.
Returns
The bool component is true if the insertion took place and false if the assignment took place. The iterator component points at the element inserted or updated.

◆ insert_or_assign() [2/2]

template<typename KeyType , typename ValueType , typename Hash , typename KeyEqual >
template<typename OtherKeyType , typename OtherValueType , typename >
auto pstore::index::hamt_map< KeyType, ValueType, Hash, KeyEqual >::insert_or_assign ( transaction_base transaction,
OtherKeyType const &  key,
OtherValueType const &  value 
) -> std::pair<iterator, bool>

If a key equivalent to key already exists in the container, assigns value to the mapped type.

If the key does not exist, inserts the new value as if by insert(). If insertion occurs, all iterators are invalidated.

Template Parameters
OtherKeyTypeA type whose serialized representation is compatible with KeyType.
OtherValueTypeA type whose serialized representation is compatible with ValueType.
Parameters
transactionThe transaction to which new data will be appended.
keyThe key the used both to look up and to insert if not found.
valueThe value that will be associated with 'key' after the call.
Returns
The bool component is true if the insertion took place and false if the assignment took place. The iterator component points at the element inserted or updated.

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