Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A > Class Template Reference

Unordered map from Key to T. More...

#include <concurrent_hash_map.h>

Inheritance diagram for tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >:

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
 

Public Types

typedef Key key_type
 
typedef T mapped_type
 
typedef std::pair< const Key, T > value_type
 
typedef hash_map_base::size_type size_type
 
typedef ptrdiff_t difference_type
 
typedef value_type * pointer
 
typedef const value_type * const_pointer
 
typedef value_type & reference
 
typedef const value_type & const_reference
 
typedef
internal::hash_map_iterator
< concurrent_hash_map,
value_type > 
iterator
 
typedef
internal::hash_map_iterator
< concurrent_hash_map, const
value_type > 
const_iterator
 
typedef
internal::hash_map_range
< iterator > 
range_type
 
typedef
internal::hash_map_range
< const_iterator > 
const_range_type
 
typedef Allocator allocator_type
 

Public Member Functions

 concurrent_hash_map (const allocator_type &a=allocator_type())
 Construct empty table.
 
 concurrent_hash_map (size_type n, const allocator_type &a=allocator_type())
 Construct empty table with n preallocated buckets. This number serves also as initial concurrency level.
 
 concurrent_hash_map (const concurrent_hash_map &table, const allocator_type &a=allocator_type())
 Copy constructor.
 
template<typename I >
 concurrent_hash_map (I first, I last, const allocator_type &a=allocator_type())
 Construction with copying iteration range and given allocator instance.
 
 concurrent_hash_map (const std::initializer_list< value_type > &il, const allocator_type &a=allocator_type())
 Construct empty table with n preallocated buckets. This number serves also as initial concurrency level.
 
concurrent_hash_mapoperator= (const concurrent_hash_map &table)
 Assignment.
 
concurrent_hash_mapoperator= (const std::initializer_list< value_type > &il)
 Assignment.
 
void rehash (size_type n=0)
 Rehashes and optionally resizes the whole table. More...
 
void clear ()
 Clear table.
 
 ~concurrent_hash_map ()
 Clear table and destroy it.
 
range_type range (size_type grainsize=1)
 
const_range_type range (size_type grainsize=1) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
std::pair< iterator, iterator > equal_range (const Key &key)
 
std::pair< const_iterator,
const_iterator > 
equal_range (const Key &key) const
 
size_type size () const
 Number of items in table.
 
bool empty () const
 True if size()==0.
 
size_type max_size () const
 Upper bound on size.
 
size_type bucket_count () const
 Returns the current number of buckets.
 
allocator_type get_allocator () const
 return allocator object
 
void swap (concurrent_hash_map &table)
 swap two instances. Iterators are invalidated
 
size_type count (const Key &key) const
 Return count of items (0 or 1)
 
bool find (const_accessor &result, const Key &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...
 
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...
 
template<typename I >
void insert (I first, I last)
 Insert range [first, last)
 
bool erase (const Key &key)
 Erase item. More...
 
bool erase (const_accessor &item_accessor)
 Erase item by const_accessor. More...
 
bool erase (accessor &item_accessor)
 Erase item by accessor. More...
 

Protected Types

typedef Allocator::template
rebind< node >::other 
node_allocator_type
 

Protected Member Functions

void delete_node (node_base *n)
 
nodesearch_bucket (const key_type &key, bucket *b) const
 
void rehash_bucket (bucket *b_new, const hashcode_t h)
 
bool lookup (bool op_insert, const Key &key, const T *t, const_accessor *result, bool write)
 Insert or find item and optionally acquire a lock on the item.
 
bool exclude (const_accessor &item_accessor)
 delete item by accessor
 
template<typename I >
std::pair< I, I > internal_equal_range (const Key &key, I end) const
 Returns an iterator for an item defined by the key, or for the next item after it (if upper==true)
 
void internal_copy (const concurrent_hash_map &source)
 Copy "source" to *this, where *this must start out empty.
 
template<typename I >
void internal_copy (I first, I last)
 
const_pointer internal_fast_find (const Key &key) const
 Fast find when no concurrent erasure is used. For internal use inside TBB only! More...
 

Protected Attributes

node_allocator_type my_allocator
 
HashCompare my_hash_compare
 

Friends

template<typename Container , typename Value >
class internal::hash_map_iterator
 
template<typename I >
class internal::hash_map_range
 
class const_accessor
 

Detailed Description

template<typename Key, typename T, typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
class tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >

Unordered map from Key to T.

concurrent_hash_map is associative container with concurrent access.
Compatibility
The class meets all Container Requirements from C++ Standard (See ISO/IEC 14882:2003(E), clause 23.1).
Exception Safety
  • Hash function is not permitted to throw an exception. User-defined types Key and T are forbidden from throwing an exception in destructors.
  • If exception happens during insert() operations, it has no effect (unless exception raised by HashCompare::hash() function during grow_segment).
  • If exception happens during operator=() operation, the container can have a part of source items, and methods size() and empty() can return wrong results.
Changes since TBB 2.1
  • Replaced internal algorithm and data structure. Patent is pending.
  • Added buckets number argument for constructor
Changes since TBB 2.0
  • Fixed exception-safety
  • Added template argument for allocator
  • Added allocator argument in constructors
  • Added constructor from a range of iterators
  • Added several new overloaded insert() methods
  • Added get_allocator()
  • Added swap()
  • Added count()
  • Added overloaded erase(accessor &) and erase(const_accessor&)
  • Added equal_range() [const]
  • Added [const_]pointer, [const_]reference, and allocator_type types
  • Added global functions: operator==(), operator!=(), and swap()

Member Function Documentation

template<typename Key , typename T , typename HashCompare , typename A >
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::erase ( const Key &  key)

Erase item.

Return true if item was erased by particularly this call.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::bucket_accessor::is_writer().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::erase ( const_accessor item_accessor)
inline

Erase item by const_accessor.

Return true if item was erased by particularly this call.

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::erase ( accessor item_accessor)
inline

Erase item by accessor.

Return true if item was erased by particularly this call.

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::find ( const_accessor result,
const Key &  key 
) const
inline

Find item and acquire a read lock on the item.

Return true if item is found, false otherwise.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::find ( accessor result,
const Key &  key 
)
inline

Find item and acquire a write lock on the item.

Return true if item is found, false otherwise.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::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.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::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.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::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.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::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.

References tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::const_accessor::release().

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
bool tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::insert ( const value_type &  value)
inline

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

Returns true if item is inserted.

template<typename Key , typename T , typename HashCompare = tbb_hash_compare<Key>, typename A = tbb_allocator<std::pair<Key, T> >>
const_pointer tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::internal_fast_find ( const Key &  key) const
inlineprotected

Fast find when no concurrent erasure is used. For internal use inside TBB only!

Return pointer to item with given key, or NULL if no such item exists. Must not be called concurrently with erasure operations.

template<typename Key , typename T , typename HashCompare , typename A >
void tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::rehash ( size_type  n = 0)

Rehashes and optionally resizes the whole table.

Useful to optimize performance before or after concurrent operations. Also enables using of find() and count() concurrent methods in serial context.


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

Copyright © 2005-2014 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.