Metall  v0.29
A persistent memory allocator for data-centric analytics
metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks > Class Template Reference

A concurrent map container which can be stored in persistent memory. This container does not allocate mutex objects internally, but allocates them as static objects. To achieve high concurrency, this container allocates multiple banks, where a bank consists of an actual STL map object and a mutex object. More...

#include </home/runner/work/metall/metall/include/metall/container/concurrent_map.hpp>

Public Types

using key_type = typename internal_map_type::key_type
 A key type. More...
 
using mapped_type = typename internal_map_type::mapped_type
 A mapped type. More...
 
using value_type = typename internal_map_type::value_type
 A value type (i.e., std::pair<const key_type, mapped_type>). More...
 
using size_type = typename internal_map_type::size_type
 A unsigned integer type (usually std::size_t). More...
 
using allocator_type = _allocator
 An allocator type. More...
 
using const_iterator = metall::utility::container_of_containers_iterator_adaptor< typename banked_map_type::const_iterator, typename internal_map_type::const_iterator >
 A const iterator type. More...
 

Public Member Functions

 concurrent_map (const _allocator &allocator=_allocator())
 
size_type count (const key_type &key) const
 Returns the number of elements matching specific key. More...
 
size_type size () const
 Returns the number of elements in the container. More...
 
bool insert (value_type &&value)
 Inserts element into the container if the container doesn't already contain an element with an equivalent key. More...
 
std::pair< mapped_type &, std::unique_lock< std::mutex > > scoped_edit (const key_type &key)
 Provides a way to edit an element exclusively. If no element exists with an equivalent key, this container creates a new element with key. More...
 
void edit (const key_type &key, const std::function< void(mapped_type &mapped_value)> &editor)
 Provides a way to edit an element exclusively. If no element exists with an equivalent key, this container creates a new element with key. More...
 
const_iterator cbegin () const
 Returns an iterator to the first element of the map. If the container is empty, the returned iterator will be equal to end(). More...
 
const_iterator cend () const
 Returns an iterator to the element following the last element of the map. This element acts as a placeholder; attempting to access it results in undefined behavior. More...
 
const_iterator find (const key_type &key) const
 Finds an element with an equivalent key. More...
 
allocator_type get_allocator () const
 Returns the allocator associated with the container. More...
 

Detailed Description

template<typename _key_type, typename _mapped_type, typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
class metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >

A concurrent map container which can be stored in persistent memory. This container does not allocate mutex objects internally, but allocates them as static objects. To achieve high concurrency, this container allocates multiple banks, where a bank consists of an actual STL map object and a mutex object.

Template Parameters
_key_typeA key type.
_mapped_typeA mapped type.
_compareA key compare.
_bank_no_hasherA key hasher.
_allocatorAn allocator.
k_num_banksThe number of banks to be allocated.
Examples
concurrent_map.cpp.

Member Typedef Documentation

◆ key_type

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::key_type = typename internal_map_type::key_type

A key type.

◆ mapped_type

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::mapped_type = typename internal_map_type::mapped_type

A mapped type.

◆ value_type

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::value_type = typename internal_map_type::value_type

A value type (i.e., std::pair<const key_type, mapped_type>).

◆ size_type

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::size_type = typename internal_map_type::size_type

A unsigned integer type (usually std::size_t).

◆ allocator_type

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::allocator_type = _allocator

An allocator type.

◆ const_iterator

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
using metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::const_iterator = metall::utility::container_of_containers_iterator_adaptor< typename banked_map_type::const_iterator, typename internal_map_type::const_iterator>

A const iterator type.

Constructor & Destructor Documentation

◆ concurrent_map()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::concurrent_map ( const _allocator &  allocator = _allocator())
inlineexplicit

Member Function Documentation

◆ count()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
size_type metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::count ( const key_type key) const
inline

Returns the number of elements matching specific key.

Parameters
keyA key value of the elements to count.
Returns
The number of elements with key that compares equivalent to key, which is either 1 or 0.

◆ size()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
size_type metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::size ( ) const
inline

Returns the number of elements in the container.

Returns
The number of elements in the container.

◆ insert()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
bool metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::insert ( value_type &&  value)
inline

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

Parameters
valueAn element value to insert.
Returns
A bool denoting whether the insertion took place.

◆ scoped_edit()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
std::pair<mapped_type &, std::unique_lock<std::mutex> > metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::scoped_edit ( const key_type key)
inline

Provides a way to edit an element exclusively. If no element exists with an equivalent key, this container creates a new element with key.

Parameters
keyA key of the element to edit.
Returns
A pair of a reference to the element and a mutex ownership wrapper.

◆ edit()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
void metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::edit ( const key_type key,
const std::function< void(mapped_type &mapped_value)> &  editor 
)
inline

Provides a way to edit an element exclusively. If no element exists with an equivalent key, this container creates a new element with key.

Parameters
keyA key of the element to edit.
editorA function object which edits an element.

◆ cbegin()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
const_iterator metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::cbegin ( ) const
inline

Returns an iterator to the first element of the map. If the container is empty, the returned iterator will be equal to end().

Returns
A const iterator to the first element.

◆ cend()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
const_iterator metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::cend ( ) const
inline

Returns an iterator to the element following the last element of the map. This element acts as a placeholder; attempting to access it results in undefined behavior.

Returns
A const iterator to the element following the last element.

◆ find()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
const_iterator metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::find ( const key_type key) const
inline

Finds an element with an equivalent key.

Parameters
keyA key value of the element to search for
Returns
An iterator to an element with an equivalent key. If no such element is found, the returned iterator will be equal to end().

◆ get_allocator()

template<typename _key_type , typename _mapped_type , typename _compare = std::less<_key_type>, typename _bank_no_hasher = std::hash<_key_type>, typename _allocator = std::allocator<std::pair<const _key_type, _mapped_type>>, int k_num_banks = 1024>
allocator_type metall::container::concurrent_map< _key_type, _mapped_type, _compare, _bank_no_hasher, _allocator, k_num_banks >::get_allocator ( ) const
inline

Returns the allocator associated with the container.

Returns
An object of the associated allocator.

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