21 #ifndef __TBB_concurrent_hash_map_H 22 #define __TBB_concurrent_hash_map_H 28 #include __TBB_STD_SWAP_HEADER 37 #if __TBB_INITIALIZER_LISTS_PRESENT 38 #include <initializer_list> 40 #if TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 49 namespace interface5 {
51 template<
typename Key,
typename T,
typename HashCompare = tbb_hash_compare<Key>,
typename A = tbb_allocator<std::pair<Key, T> > >
98 static size_type const embedded_buckets = 1<<embedded_block;
114 bucket my_embedded_segment[embedded_buckets];
122 std::memset(
this, 0, pointers_per_table*
sizeof(
segment_ptr_t)
123 +
sizeof(my_size) +
sizeof(my_mask)
124 + embedded_buckets*
sizeof(
bucket) );
125 for(
size_type i = 0; i < embedded_block; i++ )
126 my_table[i] = my_embedded_segment + segment_base(i);
127 my_mask = embedded_buckets - 1;
128 __TBB_ASSERT( embedded_block <= first_block,
"The first block number must include embedded blocks");
131 my_info_restarts = 0;
132 my_info_rehashes = 0;
153 return reinterpret_cast<uintptr_t>(ptr) > uintptr_t(63);
158 if( is_initial ) std::memset( static_cast<void*>(ptr), 0, sz*
sizeof(
bucket) );
159 else for(
size_type i = 0; i < sz; i++, ptr++) {
160 *reinterpret_cast<intptr_t*>(&ptr->
mutex) = 0;
177 if( my_segment_ptr ) *my_segment_ptr = 0;
187 __TBB_ASSERT( !is_valid(my_table[k]),
"Wrong concurrent assignment");
188 if( k >= first_block ) {
189 sz = segment_size( k );
191 init_buckets( ptr, sz, is_initial );
195 __TBB_ASSERT( k == embedded_block,
"Wrong segment index" );
196 sz = segment_size( first_block );
198 init_buckets( ptr, sz - embedded_buckets, is_initial );
199 ptr -= segment_base(embedded_block);
210 h -= segment_base(
s);
212 __TBB_ASSERT( is_valid(seg),
"hashcode must be cut by valid mask for allocated segments" );
232 return check_rehashing_collision(
h, m_old, m = m_now );
239 if( (
h & m_old) != (
h & m) ) {
242 for( ++m_old; !(
h & m_old); m_old <<= 1 )
244 m_old = (m_old<<1) - 1;
261 add_to_bucket( b, n );
265 __TBB_ASSERT( is_valid(my_table[new_seg-1]),
"new allocations must not publish new mask until segment has allocated");
268 &&
as_atomic(my_table[new_seg]).compare_and_swap(is_allocating, NULL) == NULL )
276 if( !buckets-- )
return;
277 bool is_initial = !my_size;
278 for(
size_type m = my_mask; buckets > m; m = my_mask )
279 enable_segment( segment_index_of( m+1 ), is_initial );
286 for(
size_type i = 0; i < embedded_buckets; i++)
288 for(
size_type i = embedded_block; i < pointers_per_table; i++)
293 template<
typename Iterator>
299 template<
typename Container,
typename Value>
301 :
public std::iterator<std::forward_iterator_tag,Value>
304 typedef typename Container::node
node;
308 template<
typename C,
typename T,
typename U>
311 template<
typename C,
typename T,
typename U>
314 template<
typename C,
typename T,
typename U>
317 template<
typename C,
typename U>
324 size_t k = my_index+1;
325 __TBB_ASSERT( my_bucket,
"advancing an invalid iterator?");
326 while( k <= my_map->my_mask ) {
330 else my_bucket = my_map->get_bucket( k );
331 my_node = static_cast<node*>( my_bucket->node_list );
333 my_index = k;
return;
337 my_bucket = 0; my_node = 0; my_index = k;
339 #if !defined(_MSC_VER) || defined(__INTEL_COMPILER) 340 template<
typename Key,
typename T,
typename HashCompare,
typename A>
345 const Container *my_map;
363 my_map(other.my_map),
364 my_index(other.my_index),
365 my_bucket(other.my_bucket),
366 my_node(other.my_node)
368 Value& operator*()
const {
370 return my_node->item;
383 template<
typename Container,
typename Value>
388 my_node( static_cast<
node*>(n) )
394 template<
typename Container,
typename Value>
396 my_node = static_cast<node*>( my_node->next );
397 if( !my_node ) advance_to_next_bucket();
401 template<
typename Container,
typename T,
typename U>
406 template<
typename Container,
typename T,
typename U>
413 template<
typename Iterator>
414 class hash_map_range {
443 r.my_end =
my_begin = r.my_midpoint;
445 __TBB_ASSERT( !r.empty(),
"Splitting despite the range is not divisible" );
459 my_begin( Iterator( map, 0, map.my_embedded_segment, map.my_embedded_segment->node_list ) ),
460 my_end( Iterator( map, map.my_mask + 1, 0, 0 ) ),
463 __TBB_ASSERT( grainsize_>0,
"grainsize must be positive" );
472 template<
typename Iterator>
475 size_t m = my_end.my_index-my_begin.my_index;
476 if( m > my_grainsize ) {
477 m = my_begin.my_index + m/2u;
479 my_midpoint = Iterator(*my_begin.my_map,m,b,b->
node_list);
481 my_midpoint = my_end;
483 __TBB_ASSERT( my_begin.my_index <= my_midpoint.my_index,
484 "my_begin is after my_midpoint" );
486 "my_midpoint is after my_end" );
487 __TBB_ASSERT( my_begin != my_midpoint || my_begin == my_end,
488 "[my_begin, my_midpoint) range should not be empty" );
494 #if _MSC_VER && !defined(__INTEL_COMPILER) 496 #pragma warning( push ) 497 #pragma warning( disable: 4127 ) 530 template<
typename Key,
typename T,
typename HashCompare,
typename Allocator>
532 template<
typename Container,
typename Value>
548 typedef internal::hash_map_iterator<concurrent_hash_map,value_type>
iterator;
549 typedef internal::hash_map_iterator<concurrent_hash_map,const value_type>
const_iterator;
565 #if __TBB_CPP11_RVALUE_REF_PRESENT 568 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 569 template<
typename... Args>
570 node( Args&&... args ) :
item(std::forward<Args>(args)...) {}
571 #if __TBB_COPY_FROM_NON_CONST_REF_BROKEN 573 #endif //__TBB_COPY_FROM_NON_CONST_REF_BROKEN 574 #endif //__TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 575 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 580 void *ptr = a.allocate(1);
595 return new( allocator )
node(
key, *t);
598 #if __TBB_CPP11_RVALUE_REF_PRESENT 602 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 603 template<
typename... Args>
605 return new( allocator )
node(std::forward<Args>(args)...);
607 #endif //__TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 608 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 611 return new( allocator )
node(
key);
615 __TBB_ASSERT(
false,
"this dummy function should not be called");
622 n = static_cast<node*>( n->next );
637 && try_acquire(
my_b->mutex,
true ) )
645 bool is_writer() {
return bucket::scoped_t::is_writer; }
653 __TBB_ASSERT(
h > 1,
"The lowermost buckets can't be rehashed" );
669 bmask = bmask==0? 1 : ( 1u<<(
__TBB_Log2( bmask )+1 ) ) - 1;
670 __TBB_ASSERT( (c & bmask) == (
h & bmask),
"hash() function changed for key in table" );
672 if( (c &
mask) ==
h ) {
674 if( !b_old.upgrade_to_writer() ) {
788 #if __TBB_CPP11_RVALUE_REF_PRESENT 808 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 829 #if __TBB_INITIALIZER_LISTS_PRESENT 834 call_clear_on_leave scope_guard(
this);
836 scope_guard.dismiss();
847 #endif //__TBB_INITIALIZER_LISTS_PRESENT 858 #if __TBB_CPP11_RVALUE_REF_PRESENT 870 this->
swap(moved_copy);
875 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 877 #if __TBB_INITIALIZER_LISTS_PRESENT 884 #endif //__TBB_INITIALIZER_LISTS_PRESENT 949 return const_cast<concurrent_hash_map*>(
this)->lookup(
false,
key, NULL, &result,
false, &
do_not_allocate_node );
993 #if __TBB_CPP11_RVALUE_REF_PRESENT 1012 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 1015 template<
typename... Args>
1022 template<
typename... Args>
1029 template<
typename... Args>
1033 #endif //__TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 1034 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 1037 template<
typename I>
1043 #if __TBB_INITIALIZER_LISTS_PRESENT 1044 void insert( std::initializer_list<value_type> il ) {
1046 insert( il.begin(), il.end() );
1048 #endif //__TBB_INITIALIZER_LISTS_PRESENT 1057 return exclude( item_accessor );
1063 return exclude( item_accessor );
1078 #if __TBB_CPP11_RVALUE_REF_PRESENT 1079 template<
typename Accessor>
1085 #if __TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 1086 template<
typename Accessor,
typename... Args>
1092 #endif //__TBB_CPP11_VARIADIC_TEMPLATES_PRESENT 1093 #endif //__TBB_CPP11_RVALUE_REF_PRESENT 1099 template<
typename I>
1105 template<
typename I>
1116 __TBB_ASSERT((m&(m+1))==0,
"data structure is invalid");
1122 if(
lock.try_acquire( b->
mutex,
true ) ) {
1124 const_cast<concurrent_hash_map*>(
this)->rehash_bucket( b,
h & m );
1138 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1139 bool concurrent_hash_map<Key,T,HashCompare,A>::lookup(
bool op_insert,
const Key &
key,
const T *t,
const_accessor *result,
bool write,
node* (*allocate_node)(
node_allocator_type& ,
const Key&,
const T*),
node *tmp_n ) {
1148 __TBB_ASSERT((m&(m+1))==0,
"data structure is invalid");
1149 return_value =
false;
1154 n = search_bucket(
key, b() );
1159 tmp_n = allocate_node(my_allocator,
key, t);
1161 if( !b.
is_writer() && !b.upgrade_to_writer() ) {
1163 n = search_bucket(
key, b() );
1165 b.downgrade_to_reader();
1169 if( check_mask_race(
h, m) )
1172 grow_segment = insert_new_node( b(), n = tmp_n, m );
1174 return_value =
true;
1178 if( check_mask_race(
h, m ) )
1182 return_value =
true;
1185 if( !result )
goto check_growth;
1188 if( !result->try_acquire( n->mutex, write ) ) {
1190 if( result->try_acquire( n->mutex, write ) )
break;
1191 if( !backoff.bounded_pause() ) {
1194 __TBB_ASSERT( !op_insert || !return_value,
"Can't acquire new item in locked bucket?" );
1206 if( grow_segment ) {
1207 #if __TBB_STATISTICS 1210 enable_segment( grow_segment );
1213 delete_node( tmp_n );
1214 return return_value;
1217 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1218 template<
typename I>
1222 __TBB_ASSERT((m&(m+1))==0,
"data structure is invalid");
1227 b = get_bucket(
h &= m );
1229 node *n = search_bucket(
key, b );
1231 return std::make_pair(end_, end_);
1232 iterator lower(*
this,
h, b, n), upper(lower);
1233 return std::make_pair(lower, ++upper);
1236 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1246 while( *
p && *
p != n )
1249 if( check_mask_race(
h, m ) )
1260 item_accessor.upgrade_to_writer();
1266 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1278 while( is_valid(n) && !my_hash_compare.equal(
key, static_cast<node*>(n)->item.first ) ) {
1283 if( check_mask_race(
h, m ) )
1287 else if( !b.
is_writer() && !b.upgrade_to_writer() ) {
1288 if( check_mask_race(
h, m ) )
1296 typename node::scoped_t item_locker( n->
mutex,
true );
1303 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1309 internal_swap(table);
1312 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1318 bucket *bp = get_bucket( b );
1319 for(; b <=
mask; b++, bp++ ) {
1322 __TBB_ASSERT( *reinterpret_cast<intptr_t*>(&bp->
mutex) == 0,
"concurrent or unexpectedly terminated operation during rehash() execution" );
1326 __TBB_ASSERT(
h > 1,
"The lowermost buckets can't be rehashed" );
1328 b_old = get_bucket(
h &= m );
1331 mark_rehashed_levels(
h );
1333 hashcode_t c = my_hash_compare.hash( static_cast<node*>(q)->item.first );
1334 if( (c &
mask) !=
h ) {
1338 add_to_bucket( b_new, q );
1339 }
else p = &q->next;
1343 #if TBB_USE_PERFORMANCE_WARNINGS 1344 int current_size =
int(my_size), buckets =
int(
mask)+1, empty_buckets = 0, overpopulated_buckets = 0;
1345 static bool reported =
false;
1347 #if TBB_USE_ASSERT || TBB_USE_PERFORMANCE_WARNINGS 1348 for( b = 0; b <=
mask; b++ ) {
1349 if( b & (b-2) ) ++bp;
1350 else bp = get_bucket( b );
1352 __TBB_ASSERT( *reinterpret_cast<intptr_t*>(&bp->
mutex) == 0,
"concurrent or unexpectedly terminated operation during rehash() execution" );
1354 #if TBB_USE_PERFORMANCE_WARNINGS 1356 else if( n->
next ) overpopulated_buckets++;
1359 for( ; is_valid(n); n = n->
next ) {
1360 hashcode_t h = my_hash_compare.hash( static_cast<node*>(n)->item.first ) &
mask;
1361 __TBB_ASSERT(
h == b,
"hash() function changed for key in table or internal error" );
1365 #endif // TBB_USE_ASSERT || TBB_USE_PERFORMANCE_WARNINGS 1366 #if TBB_USE_PERFORMANCE_WARNINGS 1367 if( buckets > current_size) empty_buckets -= buckets - current_size;
1368 else overpopulated_buckets -= current_size - buckets;
1369 if( !reported && buckets >= 512 && ( 2*empty_buckets > current_size || 2*overpopulated_buckets > current_size ) ) {
1371 "Performance is not optimal because the hash function produces bad randomness in lower bits in %s.\nSize: %d Empties: %d Overlaps: %d",
1373 typeid(*this).name(),
1375 "concurrent_hash_map",
1377 current_size, empty_buckets, overpopulated_buckets );
1383 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1386 __TBB_ASSERT((m&(m+1))==0,
"data structure is invalid");
1387 #if TBB_USE_ASSERT || TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 1388 #if TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 1389 int current_size =
int(my_size), buckets =
int(m)+1, empty_buckets = 0, overpopulated_buckets = 0;
1390 static bool reported =
false;
1395 if( b & (b-2) ) ++bp;
1396 else bp = get_bucket( b );
1399 __TBB_ASSERT( *reinterpret_cast<intptr_t*>(&bp->
mutex) == 0,
"concurrent or unexpectedly terminated operation during clear() execution" );
1400 #if TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 1403 else if( n->
next ) overpopulated_buckets++;
1405 #if __TBB_EXTRA_DEBUG 1406 for(; is_valid(n); n = n->
next ) {
1407 hashcode_t h = my_hash_compare.hash( static_cast<node*>(n)->item.first );
1413 #if TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 1414 #if __TBB_STATISTICS 1415 printf(
"items=%d buckets: capacity=%d rehashed=%d empty=%d overpopulated=%d" 1416 " concurrent: resizes=%u rehashes=%u restarts=%u\n",
1417 current_size,
int(m+1), buckets, empty_buckets, overpopulated_buckets,
1418 unsigned(my_info_resizes),
unsigned(my_info_rehashes),
unsigned(my_info_restarts) );
1419 my_info_resizes = 0;
1420 my_info_restarts = 0;
1421 my_info_rehashes = 0;
1423 if( buckets > current_size) empty_buckets -= buckets - current_size;
1424 else overpopulated_buckets -= current_size - buckets;
1425 if( !reported && buckets >= 512 && ( 2*empty_buckets > current_size || 2*overpopulated_buckets > current_size ) ) {
1427 "Performance is not optimal because the hash function produces bad randomness in lower bits in %s.\nSize: %d Empties: %d Overlaps: %d",
1429 typeid(*this).name(),
1431 "concurrent_hash_map",
1433 current_size, empty_buckets, overpopulated_buckets );
1437 #endif // TBB_USE_ASSERT || TBB_USE_PERFORMANCE_WARNINGS || __TBB_STATISTICS 1440 __TBB_ASSERT(
s+1 == pointers_per_table || !my_table[
s+1],
"wrong mask or concurrent grow" );
1443 __TBB_ASSERT( is_valid( my_table[
s] ),
"wrong mask or concurrent grow" );
1447 for(
node_base *n = buckets_ptr[i].node_list; is_valid(n); n = buckets_ptr[i].
node_list ) {
1451 if(
s >= first_block)
1453 else if(
s == embedded_block && embedded_block != first_block )
1454 alloc.
deallocate( buckets_ptr, segment_size(first_block)-embedded_buckets );
1455 if(
s >= embedded_block ) my_table[
s] = 0;
1457 my_mask = embedded_buckets - 1;
1460 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1463 if( my_mask ==
mask ) {
1465 bucket *dst = 0, *src = 0;
1466 bool rehash_required =
false;
1468 if( k & (k-2) ) ++dst,src++;
1469 else { dst = get_bucket( k ); src = source.
get_bucket( k ); }
1471 node *n = static_cast<node*>( src->node_list );
1473 rehash_required =
true;
1475 }
else for(; n; n = static_cast<node*>( n->next ) ) {
1476 add_to_bucket( dst,
new( my_allocator )
node(n->
item.first, n->
item.second) );
1480 if( rehash_required ) rehash();
1484 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1485 template<
typename I>
1487 reserve( reserve_size );
1490 hashcode_t h = my_hash_compare.hash( (*first).first );
1491 bucket *b = get_bucket(
h & m );
1494 add_to_bucket( b, n );
1504 template<
typename Key,
typename T,
typename HashCompare,
typename A1,
typename A2>
1506 if(a.
size() != b.
size())
return false;
1509 for(; i != i_end; ++i) {
1511 if( j == j_end || !(i->second == j->second) )
return false;
1516 template<
typename Key,
typename T,
typename HashCompare,
typename A1,
typename A2>
1518 {
return !(a == b); }
1520 template<
typename Key,
typename T,
typename HashCompare,
typename A>
1524 #if _MSC_VER && !defined(__INTEL_COMPILER) 1525 #pragma warning( pop ) 1526 #endif // warning 4127 is back void acquire(concurrent_hash_map *base, const hashcode_t h, bool writer=false)
find a bucket by masked hashcode, optionally rehash, and acquire the lock
concurrent_hash_map(concurrent_hash_map &&table, const allocator_type &a)
Move constructor.
hash_map_range(hash_map_range< U > &r)
type conversion
segments_table_t my_table
Segment pointers table. Also prevents false sharing between my_mask and my_size.
const Iterator & end() const
intptr_t __TBB_Log2(uintptr_t x)
std::pair< iterator, iterator > equal_range(const Key &key)
bool erase(accessor &item_accessor)
Erase item by accessor.
Allocator::template rebind< node >::other node_allocator_type
bool empty() const
True if size()==0.
friend bool is_write_access_needed(accessor const &)
T itt_hide_load_word(const T &src)
segment_index_t insert_new_node(bucket *b, node_base *n, hashcode_t mask)
Insert a node and check for load factor.
hash_map_iterator & operator++()
reference operator *() const
Return reference to associated value in hash table.
hash_map_range(hash_map_range &r, split)
Split range.
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.
bool empty() const
True if range is empty.
HashCompare my_hash_compare
Class that implements exponential backoff.
bool emplace(accessor &result, Args &&... args)
Insert item by copying if there is no such key present already and acquire a write lock on the item.
void rehash(size_type n=0)
Rehashes and optionally resizes the whole table.
call_clear_on_leave(concurrent_hash_map *a_ch_map)
atomic< size_type > my_size
Size of container in stored items.
bucket * segment_ptr_t
Segment pointer.
static node * allocate_node_copy_construct(node_allocator_type &allocator, const Key &key, const T *t)
hash_map_node_base node_base
Node base type.
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
void __TBB_store_with_release(volatile T &location, V value)
atomic< T > & as_atomic(T &t)
void const char const char int ITT_FORMAT __itt_group_sync s
bucket my_embedded_segment[embedded_buckets]
Zero segment.
static segment_index_t segment_index_of(size_type index)
Identifiers declared inside namespace internal should never be used directly by client code.
size_t my_index
Index in hash table for current item.
size_type max_size() const
Upper bound on size.
node * my_node
Pointer to node that has current item.
Dummy type that distinguishes splitting constructor from copy constructor.
Iterator::difference_type difference_type
std::size_t size_type
Type for size of a range.
bool check_mask_race(const hashcode_t h, hashcode_t &m) const
Check for mask race.
const_pointer operator->() const
Return pointer to associated value in hash table.
mutex_t::scoped_lock scoped_t
Scoped lock type for mutex.
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 lev...
bucket_accessor(concurrent_hash_map *base, const hashcode_t h, bool writer=false)
Base class for types that should not be copied or assigned.
const value_type & const_reference
auto last(Container &c) -> decltype(begin(c))
static segment_index_t segment_base(segment_index_t k)
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
static hash_map_node_base *const rehash_req
Incompleteness flag value.
bool lookup(bool op_insert, const Key &key, const T *t, const_accessor *result, bool write, node *(*allocate_node)(node_allocator_type &, const Key &, const T *), node *tmp_n=0)
Insert or find item and optionally acquire a lock on the item.
friend const_accessor * accessor_location(accessor_not_used const &)
hash_map_node_base * next
Next node in chain.
bucket accessor is to find, rehash, acquire a lock, and access a bucket
bool is_divisible() const
True if range can be partitioned into two subranges.
const concurrent_hash_map::value_type value_type
Type of value.
static node * allocate_node_emplace_construct(node_allocator_type &allocator, Args &&... args)
void swap(concurrent_hash_map &table)
swap two instances. Iterators are invalidated
bool emplace(Args &&... args)
Insert item by copying if there is no such key present already.
internal::hash_map_iterator< concurrent_hash_map, const value_type > const_iterator
void rehash_bucket(bucket *b_new, const hashcode_t h)
static node * do_not_allocate_node(node_allocator_type &, const Key &, const T *)
concurrent_hash_map(const HashCompare &compare, const allocator_type &a=allocator_type())
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.
Allows write access to elements and combines data access, locking, and garbage collection.
Value * operator->() const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
auto first(Container &c) -> decltype(begin(c))
node * search_bucket(const key_type &key, bucket *b) const
void const char const char int ITT_FORMAT __itt_group_sync p
void release()
Set to null.
hash_map_iterator(const hash_map_iterator< Container, typename Container::value_type > &other)
Class for determining type of std::allocator<T>::value_type.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
Iterator::map_type map_type
Fast, unfair, spinning reader-writer lock with backoff and writer-preference.
Unordered map from Key to T.
void internal_swap(hash_map_base &table)
Swap hash_map_bases.
void enable_segment(segment_index_t k, bool is_initial=false)
Enable segment.
node_allocator_type my_allocator
pointer operator->() const
Return pointer to associated value in hash table.
internal::hash_map_range< iterator > range_type
internal::hash_map_iterator< concurrent_hash_map, value_type > iterator
bool insert(value_type &&value)
Insert item by copying if there is no such key present already.
friend class internal::hash_map_range
static hash_map_node_base *const empty_rehashed
Rehashed empty bucket flag.
bool is_writer()
check whether bucket is locked for write
T __TBB_load_with_acquire(const volatile T &location)
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)
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.
Range class used with concurrent_hash_map.
hash_map_base()
Constructor.
node(const Key &key, T &&t)
base class of concurrent_hash_map
hash_map_base::size_type size_type
void mark_rehashed_levels(hashcode_t h)
concurrent_hash_map(I first, I last, const HashCompare &compare, const allocator_type &a=allocator_type())
const value_type * const_pointer
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
bool empty() const
True if result is empty.
bool find(const_accessor &result, const Key &key) const
Find item and acquire a read lock on the item.
concurrent_hash_map(std::initializer_list< value_type > il, const HashCompare &compare, const allocator_type &a=allocator_type())
internal::hash_map_range< const_iterator > const_range_type
size_t size_type
Size type.
concurrent_hash_map(size_type n, const HashCompare &compare, const allocator_type &a=allocator_type())
concurrent_hash_map::value_type value_type
Type of value.
range_type range(size_type grainsize=1)
Combines data access, locking, and garbage collection.
~enable_segment_failsafe()
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.
hash_map_iterator operator++(int)
Post increment.
size_type grainsize() const
The grain size for this range.
void move(tbb_thread &t1, tbb_thread &t2)
static node * allocate_node_move_construct(node_allocator_type &allocator, const Key &key, const T *t)
size_type size() const
Number of items in table.
size_type bucket_count() const
Returns the current number of buckets.
bool insert(accessor &result, const Key &key)
Insert item (if not already present) and acquire a write lock on the item.
void advance_to_next_bucket()
concurrent_hash_map(I first, I last, const allocator_type &a=allocator_type())
Construction with copying iteration range and given allocator instance.
bool erase(const_accessor &item_accessor)
Erase item by const_accessor.
T itt_load_word_with_acquire(const tbb::atomic< T > &src)
mutex_t::scoped_lock scoped_t
Scoped lock type for mutex.
allocator_type get_allocator() const
return allocator object
void __TBB_EXPORTED_FUNC runtime_warning(const char *format,...)
Report a runtime warning.
hash_map_iterator()
Construct undefined iterator.
segment_ptr_t * my_segment_ptr
static void add_to_bucket(bucket *b, node_base *n)
Add node.
bool insert(const value_type &value)
Insert item by copying if there is no such key present already.
bucket * operator()()
get bucket pointer
friend class internal::hash_map_iterator
bool operator!=(const hash_map_iterator< Container, T > &i, const hash_map_iterator< Container, U > &j)
static void init_buckets(segment_ptr_t ptr, size_type sz, bool is_initial)
Initialize buckets.
node(const value_type &i)
const Iterator & begin() const
atomic< hashcode_t > my_mask
Hash mask = sum of allocated segment sizes - 1.
bucket * get_bucket(hashcode_t h) const
Get bucket by (masked) hashcode.
bool generic_emplace(Accessor &&result, Args &&... args)
node(const Key &key, const T &t)
const_pointer internal_fast_find(const Key &key) const
Fast find when no concurrent erasure is used. For internal use inside TBB only!
Meets requirements of a forward iterator for STL */.
~const_accessor()
Destroy result after releasing the underlying reference.
void delete_node(node_base *n)
friend bool is_write_access_needed(accessor_not_used const &)
hash_map_base::node_base node_base
#define __TBB_USE_OPTIONAL_RTTI
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle * key
enable_segment_failsafe(segments_table_t &table, segment_index_t k)
bool generic_move_insert(Accessor &&result, value_type &&value)
static size_type segment_size(segment_index_t k)
~concurrent_hash_map()
Clear table and destroy it.
spin_rw_mutex mutex_t
Mutex type.
concurrent_hash_map(const concurrent_hash_map &table, const allocator_type &a=allocator_type())
Copy constructor.
const_iterator begin() const
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
Iterator::value_type value_type
void internal_copy(const concurrent_hash_map &source)
Copy "source" to *this, where *this must start out empty.
ptrdiff_t difference_type
const Container * my_map
concurrent_hash_map over which we are iterating.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
bool operator==(const hash_map_iterator< Container, T > &i, const hash_map_iterator< Container, U > &j)
void itt_hide_store_word(T &dst, T src)
size_t hashcode_t
Type of a hash code.
const bucket * my_bucket
Pointer to bucket.
static bool is_valid(void *ptr)
void reserve(size_type buckets)
Prepare enough segments for number of buckets.
concurrent_hash_map(const allocator_type &a=allocator_type())
Construct empty table.
const_reference operator *() const
Return reference to associated value in hash table.
const_range_type range(size_type grainsize=1) const
bool erase(const Key &key)
Erase item.
size_type count(const Key &key) const
Return count of items (0 or 1)
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock
hash_map_range(const map_type &map, size_type grainsize_=1)
Init range with container and grainsize specified.
spin_rw_mutex mutex_t
Mutex type for buckets.
bool find(accessor &result, const Key &key)
Find item and acquire a write lock on the item.
void insert(I first, I last)
Insert range [first, last)
bool exclude(const_accessor &item_accessor)
delete item by accessor
friend bool is_write_access_needed(const_accessor const &)
friend const_accessor * accessor_location(const_accessor &a)
hash_map_base::bucket bucket
bool check_rehashing_collision(const hashcode_t h, hashcode_t m_old, hashcode_t m) const
Process mask race, check for rehashing collision.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int mask
concurrent_hash_map * my_ch_map
tick_count::interval_t operator-(const tick_count &t1, const tick_count &t0)
std::pair< const Key, T > value_type
concurrent_hash_map & operator=(const concurrent_hash_map &table)
Assignment.
void set_midpoint() const
Set my_midpoint to point approximately half way between my_begin and my_end.
pointer allocate(size_type n, const void *hint=0)
Allocate space for n objects, starting on a cache/sector line.
bool insert(const_accessor &result, const Key &key)
Insert item (if not already present) and acquire a read lock on the item.
bool emplace(const_accessor &result, Args &&... args)
Insert item by copying if there is no such key present already and acquire a read lock on the item.
size_t segment_index_t
Segment index type.
const_iterator end() const
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
size_t hashcode_t
Type of a hash code.
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.
static node * allocate_node_default_construct(node_allocator_type &allocator, const Key &key, const T *)
friend class const_accessor
void swap(concurrent_hash_map< Key, T, HashCompare, A > &a, concurrent_hash_map< Key, T, HashCompare, A > &b)
const_accessor()
Create empty result.
void itt_store_word_with_release(tbb::atomic< T > &dst, U src)
Iterator::reference reference
The scoped locking pattern.