PMDK C++ bindings  1.7
This is the C++ bindings documentation for PMDK's libpmemobj.
Classes | Public Member Functions | Protected Member Functions | List of all members
pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual > Class Template Reference

Persistent memory aware implementation of Intel TBB concurrent_hash_map. More...

#include <libpmemobj++/experimental/concurrent_hash_map.hpp>

Classes

class  accessor
 Allows write access to elements and combines data access, locking, and garbage collection. More...
 
class  bucket_accessor
 Bucket accessor is to find, rehash, acquire a lock, and access a bucket. More...
 
class  const_accessor
 Combines data access, locking, and garbage collection. More...
 
struct  node
 Node structure to store Key/Value pair. More...
 
class  serial_bucket_accessor
 Serial bucket accessor used to access bucket in a serial operations. More...
 

Public Member Functions

 concurrent_hash_map ()
 Construct empty table.
 
 concurrent_hash_map (size_type n)
 Construct empty table with n preallocated buckets. More...
 
 concurrent_hash_map (const concurrent_hash_map &table)
 Copy constructor.
 
 concurrent_hash_map (concurrent_hash_map &&table)
 Move constructor.
 
template<typename I >
 concurrent_hash_map (I first, I last)
 Construction table with copying iteration range.
 
 concurrent_hash_map (std::initializer_list< value_type > il)
 Construct table with initializer list.
 
void initialize (bool graceful_shutdown=false)
 Intialize persistent concurrent hash map after process restart. More...
 
concurrent_hash_mapoperator= (const concurrent_hash_map &table)
 Assignment. More...
 
concurrent_hash_mapoperator= (std::initializer_list< value_type > il)
 Assignment. More...
 
void rehash (size_type n=0)
 Rehashes and optionally resizes the whole table. More...
 
void clear ()
 Clear hash map content. More...
 
 ~concurrent_hash_map ()
 Clear table and destroy it.
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
size_type size () const
 
bool empty () const
 
size_type max_size () const
 Upper bound on size.
 
size_type bucket_count () const
 
void swap (concurrent_hash_map &table)
 Swap two instances. More...
 
size_type count (const Key &key) const
 
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
size_type count (const K &key) const
 This overload only participates in overload resolution if the qualified-id Hash::transparent_key_equal is valid and denotes a type. More...
 
bool find (const_accessor &result, const Key &key) const
 Find item and acquire a read lock on the item. More...
 
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool find (const_accessor &result, const K &key) const
 Find item and acquire a read lock on the item. More...
 
bool find (accessor &result, const Key &key)
 Find item and acquire a write lock on the item. More...
 
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool find (accessor &result, const K &key)
 Find item and acquire a write lock on the item. More...
 
bool insert (const_accessor &result, const Key &key)
 Insert item (if not already present) and acquire a read lock on the item. More...
 
bool insert (accessor &result, const Key &key)
 Insert item (if not already present) and acquire a write lock on the item. More...
 
bool insert (const_accessor &result, const value_type &value)
 Insert item by copying if there is no such key present already and acquire a read lock on the item. More...
 
bool insert (accessor &result, const value_type &value)
 Insert item by copying if there is no such key present already and acquire a write lock on the item. More...
 
bool insert (const value_type &value)
 Insert item by copying if there is no such key present already. More...
 
bool insert (const_accessor &result, value_type &&value)
 Insert item by copying if there is no such key present already and acquire a read lock on the item. More...
 
bool insert (accessor &result, value_type &&value)
 Insert item by copying if there is no such key present already and acquire a write lock on the item. More...
 
bool insert (value_type &&value)
 Insert item by copying if there is no such key present already. More...
 
template<typename I >
void insert (I first, I last)
 Insert range [first, last) More...
 
void insert (std::initializer_list< value_type > il)
 Insert initializer list. More...
 
bool erase (const Key &key)
 Remove element with corresponding key. More...
 
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool erase (const K &key)
 Remove element with corresponding key. More...
 

Protected Member Functions

template<bool OpInsert, typename K >
bool lookup (const K &key, const void *param, const_accessor *result, bool write, void(*allocate_node)(pool_base &, persistent_ptr< node > &, const void *, const node_base_ptr_t &))
 Insert or find item and optionally acquire a lock on the item.
 
void internal_copy (const concurrent_hash_map &source)
 Copy "source" to *this, where *this must start out empty.
 

Detailed Description

template<typename Key, typename T, typename Hash, typename KeyEqual>
class pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >

Persistent memory aware implementation of Intel TBB concurrent_hash_map.

Constructor & Destructor Documentation

◆ concurrent_hash_map()

template<typename Key , typename T , typename Hash , typename KeyEqual >
pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::concurrent_hash_map ( size_type  n)
inline

Construct empty table with n preallocated buckets.

This number serves also as initial concurrency level.

Member Function Documentation

◆ begin() [1/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
iterator pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::begin ( )
inline
Returns
an iterator to the beginning Not thread safe.

◆ begin() [2/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
const_iterator pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::begin ( ) const
inline
Returns
an iterator to the beginning Not thread safe.

◆ bucket_count()

template<typename Key , typename T , typename Hash , typename KeyEqual >
size_type pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::bucket_count ( ) const
inline
Returns
the current number of buckets

◆ clear()

template<typename Key , typename T , typename Hash , typename KeyEqual >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::clear

Clear hash map content.

Exceptions
std::runtime_errorin case of PMDK transaction failure Not thread safe.

◆ count() [1/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
size_type pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::count ( const K &  key) const
inline

This overload only participates in overload resolution if the qualified-id Hash::transparent_key_equal is valid and denotes a type.

This assumes that such Hash is callable with both K and Key type, and that its key_equal is transparent, which, together, allows calling this function without constructing an instance of Key

Returns
count of items (0 or 1)

◆ count() [2/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
size_type pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::count ( const Key &  key) const
inline
Returns
count of items (0 or 1)

◆ empty()

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::empty ( ) const
inline
Returns
true if size()==0.

◆ end() [1/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
iterator pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::end ( )
inline
Returns
an iterator to the end Not thread safe.

◆ end() [2/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
const_iterator pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::end ( ) const
inline
Returns
an iterator to the end Not thread safe.

◆ erase() [1/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::erase ( const K &  key)
inline

Remove element with corresponding key.

This overload only participates in overload resolution if the qualified-id Hash::transparent_key_equal is valid and denotes a type. This assumes that such Hash is callable with both K and Key type, and that its key_equal is transparent, which, together, allows calling this function without constructing an instance of Key

Returns
true if element was deleted by this call
Exceptions
std::runtime_errorin case of PMDK unable to free the memory

◆ erase() [2/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::erase ( const Key &  key)
inline

Remove element with corresponding key.

Returns
true if element was deleted by this call
Exceptions
std::runtime_errorin case of PMDK unable to free the memory

◆ find() [1/4]

template<typename Key , typename T , typename Hash , typename KeyEqual >
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::find ( accessor result,
const K &  key 
)
inline

Find item and acquire a write lock on the item.

This overload only participates in overload resolution if the qualified-id Hash::transparent_key_equal is valid and denotes a type. This assumes that such Hash is callable with both K and Key type, and that its key_equal is transparent, which, together, allows calling this function without constructing an instance of Key

Returns
true if item is found, false otherwise.

◆ find() [2/4]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::find ( accessor result,
const Key &  key 
)
inline

Find item and acquire a write lock on the item.

Returns
true if item is found, false otherwise.

◆ find() [3/4]

template<typename Key , typename T , typename Hash , typename KeyEqual >
template<typename K , typename = typename std::enable_if< internal::has_transparent_key_equal<hasher>::value, K>::type>
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::find ( const_accessor result,
const K &  key 
) const
inline

Find item and acquire a read lock on the item.

This overload only participates in overload resolution if the qualified-id Hash::transparent_key_equal is valid and denotes a type. This assumes that such Hash is callable with both K and Key type, and that its key_equal is transparent, which, together, allows calling this function without constructing an instance of Key

Returns
true if item is found, false otherwise.

◆ find() [4/4]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::find ( const_accessor result,
const Key &  key 
) const
inline

Find item and acquire a read lock on the item.

Returns
true if item is found, false otherwise.

◆ initialize()

template<typename Key , typename T , typename Hash , typename KeyEqual >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::initialize ( bool  graceful_shutdown = false)
inline

Intialize persistent concurrent hash map after process restart.

Should be called everytime after process restart. Not thread safe.

◆ insert() [1/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( accessor result,
const Key &  key 
)
inline

Insert item (if not already present) and acquire a write lock on the item.

Returns
true if item is new.
Exceptions
std::bad_allocon allocation failure.

◆ insert() [2/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( accessor result,
const value_type &  value 
)
inline

Insert item by copying if there is no such key present already and acquire a write lock on the item.

Returns
true if item is new.

◆ insert() [3/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( accessor result,
value_type &&  value 
)
inline

Insert item by copying if there is no such key present already and acquire a write lock on the item.

Returns
true if item is new.
Exceptions
std::bad_allocon allocation failure.

◆ insert() [4/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( const value_type &  value)
inline

Insert item by copying if there is no such key present already.

Returns
true if item is inserted.

◆ insert() [5/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( const_accessor result,
const Key &  key 
)
inline

Insert item (if not already present) and acquire a read lock on the item.

Returns
true if item is new.
Exceptions
std::bad_allocon allocation failure.

◆ insert() [6/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( const_accessor result,
const value_type &  value 
)
inline

Insert item by copying if there is no such key present already and acquire a read lock on the item.

Returns
true if item is new.
Exceptions
std::bad_allocon allocation failure.

◆ insert() [7/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( const_accessor result,
value_type &&  value 
)
inline

Insert item by copying if there is no such key present already and acquire a read lock on the item.

Returns
true if item is new.
Exceptions
std::bad_allocon allocation failure.

◆ insert() [8/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
template<typename I >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( first,
last 
)
inline

Insert range [first, last)

Exceptions
std::bad_allocon allocation failure.

◆ insert() [9/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( std::initializer_list< value_type >  il)
inline

Insert initializer list.

Exceptions
std::bad_allocon allocation failure.

◆ insert() [10/10]

template<typename Key , typename T , typename Hash , typename KeyEqual >
bool pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::insert ( value_type &&  value)
inline

Insert item by copying if there is no such key present already.

Returns
true if item is inserted.
Exceptions
std::bad_allocon allocation failure.

◆ operator=() [1/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
concurrent_hash_map& pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::operator= ( const concurrent_hash_map< Key, T, Hash, KeyEqual > &  table)
inline

Assignment.

Exceptions
std::runtime_errorin case of PMDK transaction failure Not thread safe.

◆ operator=() [2/2]

template<typename Key , typename T , typename Hash , typename KeyEqual >
concurrent_hash_map& pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::operator= ( std::initializer_list< value_type >  il)
inline

Assignment.

Exceptions
std::runtime_errorin case of PMDK transaction failure Not thread safe.

◆ rehash()

template<typename Key , typename T , typename Hash , typename KeyEqual >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::rehash ( size_type  n = 0)

Rehashes and optionally resizes the whole table.

Useful to optimize performance before or after concurrent operations. Not thread safe.

◆ size()

template<typename Key , typename T , typename Hash , typename KeyEqual >
size_type pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::size ( ) const
inline
Returns
number of items in table.

◆ swap()

template<typename Key , typename T , typename Hash , typename KeyEqual >
void pmem::obj::experimental::concurrent_hash_map< Key, T, Hash, KeyEqual >::swap ( concurrent_hash_map< Key, T, Hash, KeyEqual > &  table)

Swap two instances.

Iterators are invalidated. Not thread safe.


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