10 #ifndef PMEMOBJ_CONCURRENT_HASH_MAP_HPP
11 #define PMEMOBJ_CONCURRENT_HASH_MAP_HPP
15 #include <libpmemobj++/detail/pair.hpp>
25 #include <libpmemobj++/detail/persistent_pool_ptr.hpp>
33 #include <initializer_list>
38 #include <type_traits>
48 struct hash<
pmem::obj::p<T>> {
52 return hash<T>()(x.
get_ro());
62 namespace concurrent_hash_map_internal
64 template <
typename SharedMutexT>
65 class shared_mutex_scoped_lock {
66 using rw_mutex_type = SharedMutexT;
69 shared_mutex_scoped_lock(
const shared_mutex_scoped_lock &) =
delete;
70 shared_mutex_scoped_lock &
71 operator=(
const shared_mutex_scoped_lock &) =
delete;
74 shared_mutex_scoped_lock() : mutex(nullptr), is_writer(false)
79 shared_mutex_scoped_lock(rw_mutex_type &m,
bool write =
true)
86 ~shared_mutex_scoped_lock()
94 acquire(rw_mutex_type &m,
bool write =
true)
101 mutex->lock_shared();
111 rw_mutex_type *m = mutex;
125 try_acquire(rw_mutex_type &m,
bool write =
true)
130 result = write ? m.try_lock() : m.try_lock_shared();
141 rw_mutex_type *mutex;
149 template <
typename ScopedLockType>
150 using scoped_lock_upgrade_to_writer =
151 decltype(std::declval<ScopedLockType>().upgrade_to_writer());
153 template <
typename ScopedLockType>
154 using scoped_lock_has_upgrade_to_writer =
155 detail::supports<ScopedLockType, scoped_lock_upgrade_to_writer>;
157 template <
typename ScopedLockType>
158 using scoped_lock_downgrade_to_reader =
159 decltype(std::declval<ScopedLockType>().downgrade_to_reader());
161 template <
typename ScopedLockType>
162 using scoped_lock_has_downgrade_to_reader =
163 detail::supports<ScopedLockType, scoped_lock_downgrade_to_reader>;
165 template <
typename ScopedLockType,
166 bool = scoped_lock_has_upgrade_to_writer<ScopedLockType>::value
167 &&scoped_lock_has_downgrade_to_reader<ScopedLockType>::value>
168 class scoped_lock_traits {
170 using scope_lock_type = ScopedLockType;
173 initial_rw_state(
bool write)
180 upgrade_to_writer(scope_lock_type &lock)
182 return lock.upgrade_to_writer();
186 downgrade_to_reader(scope_lock_type &lock)
188 return lock.downgrade_to_reader();
192 template <
typename ScopedLockType>
193 class scoped_lock_traits<ScopedLockType, false> {
195 using scope_lock_type = ScopedLockType;
198 initial_rw_state(
bool write)
206 upgrade_to_writer(scope_lock_type &lock)
215 downgrade_to_reader(scope_lock_type &lock)
227 template <
typename Key,
typename T,
typename Hash = std::hash<Key>,
228 typename KeyEqual = std::equal_to<Key>,
229 typename MutexType = pmem::obj::shared_mutex,
230 typename ScopedLockType = concurrent_hash_map_
internal::
231 shared_mutex_scoped_lock<MutexType>>
232 class concurrent_hash_map;
235 namespace concurrent_hash_map_internal
241 if (pmemobj_tx_stage() != TX_STAGE_NONE)
243 "Function called inside transaction scope.");
246 template <
typename Hash>
247 using transparent_key_equal =
typename Hash::transparent_key_equal;
249 template <
typename Hash>
250 using has_transparent_key_equal = detail::supports<Hash, transparent_key_equal>;
252 template <
typename Hash,
typename Pred,
253 bool = has_transparent_key_equal<Hash>::value>
254 struct key_equal_type {
255 using type =
typename Hash::transparent_key_equal;
258 template <
typename Hash,
typename Pred>
259 struct key_equal_type<Hash, Pred, false> {
263 template <
typename Mutex,
typename ScopedLockType>
265 assert_not_locked(Mutex &mtx)
268 ScopedLockType scoped_lock;
269 assert(scoped_lock.try_acquire(mtx));
270 scoped_lock.release();
276 template <
typename Key,
typename T,
typename MutexType,
typename ScopedLockType>
277 struct hash_map_node {
279 using mutex_t = MutexType;
282 using scoped_t = ScopedLockType;
284 using value_type = detail::pair<const Key, T>;
287 using node_ptr_t = detail::persistent_pool_ptr<
288 hash_map_node<Key, T, mutex_t, scoped_t>>;
299 hash_map_node(
const node_ptr_t &_next,
const Key &key)
301 item(std::piecewise_construct, std::forward_as_tuple(key),
302 std::forward_as_tuple())
306 hash_map_node(
const node_ptr_t &_next,
const Key &key,
const T &t)
307 : next(_next), item(key, t)
311 hash_map_node(
const node_ptr_t &_next, value_type &&i)
312 : next(_next), item(std::move(i))
316 template <
typename... Args>
317 hash_map_node(
const node_ptr_t &_next, Args &&... args)
318 : next(_next), item(std::forward<Args>(args)...)
322 hash_map_node(
const node_ptr_t &_next,
const value_type &i)
323 : next(_next), item(i)
328 hash_map_node(
const hash_map_node &) =
delete;
331 hash_map_node &operator=(
const hash_map_node &) =
delete;
338 template <
typename Bucket>
339 class segment_traits {
342 using segment_index_t = size_t;
343 using size_type = size_t;
344 using bucket_type = Bucket;
348 constexpr
static size_type max_allocation_size = PMEMOBJ_MAX_ALLOC_SIZE;
351 constexpr
static segment_index_t first_big_block = 27;
356 constexpr
static size_type big_block_size = size_type(1)
360 static_assert((big_block_size *
sizeof(bucket_type)) <
362 "Block size exceeds max_allocation_size");
365 constexpr
static segment_index_t
366 first_block_in_segment(segment_index_t seg)
368 return seg < first_big_block
371 (segment_index_t(1) << (seg - first_big_block)) - 1);
375 constexpr
static size_type
376 blocks_in_segment(segment_index_t seg)
378 return seg < first_big_block
380 : segment_index_t(1) << (seg - first_big_block);
384 constexpr
static size_type
385 block_size(segment_index_t b)
387 return b < first_big_block ? segment_size(b ? b : 1)
393 constexpr
static segment_index_t embedded_segments = 1;
396 constexpr
static size_type embedded_buckets = 1 << embedded_segments;
399 constexpr
static segment_index_t number_of_segments = 32;
402 static const size_type first_block = 8;
405 constexpr
static segment_index_t
408 return first_block_in_segment(number_of_segments);
412 static segment_index_t
413 segment_index_of(size_type index)
415 return segment_index_t(detail::Log2(index | 1));
419 constexpr
static segment_index_t
420 segment_base(segment_index_t k)
422 return (segment_index_t(1) << k) & ~segment_index_t(1);
426 constexpr
static size_type
427 segment_size(segment_index_t k)
429 return size_type(1) << k;
432 embedded_segments < first_big_block,
433 "Number of embedded segments cannot exceed max_allocation_size");
452 template <
typename BlockTable,
typename SegmentTraits,
bool is_const>
453 class segment_facade_impl :
public SegmentTraits {
455 using traits_type = SegmentTraits;
456 using traits_type::block_size;
457 using traits_type::blocks_in_segment;
458 using traits_type::embedded_buckets;
459 using traits_type::embedded_segments;
460 using traits_type::first_block;
461 using traits_type::first_block_in_segment;
462 using traits_type::segment_base;
463 using traits_type::segment_size;
466 using table_reference =
467 typename std::conditional<is_const,
const BlockTable &,
470 using table_pointer =
471 typename std::conditional<is_const,
const BlockTable *,
474 using bucket_type =
typename traits_type::bucket_type;
475 using segment_index_t =
typename traits_type::segment_index_t;
476 using size_type =
typename traits_type::size_type;
479 segment_facade_impl(table_reference table, segment_index_t s)
480 : my_table(&table), my_seg(s)
482 assert(my_seg < traits_type::number_of_segments);
486 segment_facade_impl(
const segment_facade_impl &src)
487 : my_table(src.my_table), my_seg(src.my_seg)
491 segment_facade_impl(segment_facade_impl &&src) =
default;
494 segment_facade_impl &
495 operator=(
const segment_facade_impl &src)
497 my_table = src.my_table;
503 segment_facade_impl &
504 operator=(segment_facade_impl &&src)
506 my_table = src.my_table;
517 bucket_type &operator[](size_type i)
const
521 segment_index_t table_block = first_block_in_segment(my_seg);
522 size_type b_size = block_size(table_block);
524 table_block += i / b_size;
527 return (*my_table)[table_block][
static_cast<std::ptrdiff_t
>(i)];
533 segment_facade_impl &
546 segment_facade_impl tmp = *
this;
554 segment_facade_impl &
567 segment_facade_impl tmp = *
this;
575 segment_facade_impl &
585 segment_facade_impl &
598 return segment_facade_impl(*(this->my_table),
608 return segment_facade_impl(*(this->my_table),
616 enable(pool_base &pop)
618 assert(my_seg >= embedded_segments);
620 if (my_seg < first_block) {
621 enable_first_block(pop);
623 enable_big_segment(pop);
633 assert(my_seg >= embedded_segments);
635 if (my_seg < first_block) {
636 if (my_seg == embedded_segments) {
637 size_type sz = segment_size(first_block) -
639 delete_persistent<bucket_type[]>(
640 (*my_table)[my_seg], sz);
642 (*my_table)[my_seg] =
nullptr;
644 block_range blocks = segment_blocks(my_seg);
646 for (segment_index_t b = blocks.first;
647 b < blocks.second; ++b) {
648 if ((*my_table)[b] !=
nullptr) {
649 delete_persistent<bucket_type[]>(
650 (*my_table)[b], block_size(b));
651 (*my_table)[b] =
nullptr;
663 return segment_size(my_seg ? my_seg : 1);
674 block_range blocks = segment_blocks(my_seg);
676 for (segment_index_t b = blocks.first; b < blocks.second; ++b) {
677 if ((*my_table)[b] ==
nullptr)
685 using block_range = std::pair<segment_index_t, segment_index_t>;
691 segment_blocks(segment_index_t seg)
693 segment_index_t
begin = first_block_in_segment(seg);
695 return block_range(
begin,
begin + blocks_in_segment(seg));
699 enable_first_block(pool_base &pop)
701 assert(my_seg == embedded_segments);
703 transaction::manual tx(pop);
706 segment_size(first_block) - embedded_buckets;
707 (*my_table)[my_seg] =
708 make_persistent<bucket_type[]>(sz);
710 persistent_ptr<bucket_type> base =
711 (*my_table)[embedded_segments].raw();
713 for (segment_index_t s = my_seg + 1; s < first_block;
716 static_cast<std::ptrdiff_t
>(
718 segment_base(my_seg));
720 (*my_table)[s] = (base + off).raw();
728 enable_big_segment(pool_base &pop)
730 block_range blocks = segment_blocks(my_seg);
732 transaction::manual tx(pop);
734 for (segment_index_t b = blocks.first;
735 b < blocks.second; ++b) {
736 assert((*my_table)[b] ==
nullptr);
737 (*my_table)[b] = make_persistent<bucket_type[]>(
746 table_pointer my_table;
749 segment_index_t my_seg;
758 template <
typename Key,
typename T,
typename MutexType,
typename ScopedLockType>
759 class hash_map_base {
761 using mutex_t = MutexType;
762 using scoped_t = ScopedLockType;
765 using size_type = size_t;
768 using hashcode_type = size_t;
771 using node = hash_map_node<Key, T, mutex_t, scoped_t>;
774 using node_ptr_t = detail::persistent_pool_ptr<node>;
778 using mutex_t = MutexType;
779 using scoped_t = ScopedLockType;
785 p<std::atomic<uint64_t>> rehashed;
788 node_ptr_t node_list;
791 bucket() : node_list(nullptr)
793 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
794 VALGRIND_HG_DISABLE_CHECKING(&rehashed,
797 rehashed.get_rw() =
false;
806 is_rehashed(std::memory_order order)
808 return rehashed.get_ro().load(order);
812 set_rehashed(std::memory_order order)
814 rehashed.get_rw().store(
true, order);
818 bucket(
const bucket &) =
delete;
821 bucket &operator=(
const bucket &) =
delete;
825 using segment_traits_t = segment_traits<bucket>;
828 using segment_index_t =
typename segment_traits_t::segment_index_t;
831 static const size_type embedded_buckets =
832 segment_traits_t::embedded_buckets;
835 static const size_type first_block = segment_traits_t::first_block;
838 constexpr
static size_type block_table_size =
839 segment_traits_t::number_of_blocks();
842 using segment_ptr_t = persistent_ptr<bucket[]>;
845 using bucket_ptr_t = persistent_ptr<bucket>;
848 using blocks_table_t = segment_ptr_t[block_table_size];
855 p<int64_t> size_diff = 0;
856 std::aligned_storage<56, 8> padding;
859 using tls_t = detail::enumerable_thread_specific<tls_data_t>;
861 enum feature_flags : uint32_t { FEATURE_CONSISTENT_SIZE = 1 };
866 p<uint32_t> incompat;
872 p<uint64_t> my_pool_uuid;
876 features layout_features;
880 std::aligned_storage<
sizeof(size_t),
sizeof(
size_t)>::type
885 std::atomic<hashcode_type> my_mask;
888 std::size_t value_size;
891 std::aligned_storage<24, 8>::type padding1;
897 blocks_table_t my_table;
902 std::atomic<size_type> my_size;
905 std::aligned_storage<24, 8>::type padding2;
908 persistent_ptr<tls_t> tls_ptr;
915 p<size_t> on_init_size;
918 std::aligned_storage<40, 8>::type reserved;
921 segment_enable_mutex_t my_segment_enable_mutex;
924 bucket my_embedded_segment[embedded_buckets];
929 static constexpr features
932 return {FEATURE_CONSISTENT_SIZE, 0};
935 const std::atomic<hashcode_type> &
936 mask() const noexcept
941 std::atomic<hashcode_type> &
950 return my_size.load(std::memory_order_relaxed);
956 assert(this->tls_ptr !=
nullptr);
957 return this->tls_ptr->local().size_diff;
964 assert(this->tls_ptr !=
nullptr);
966 pool_base pop = pool_base{pmemobj_pool_by_ptr(
this)};
968 int64_t last_run_size = 0;
969 for (
auto &data : *tls_ptr)
970 last_run_size += data.size_diff;
973 assert(last_run_size >= 0 ||
974 static_cast<int64_t
>(
static_cast<size_t>(last_run_size) +
978 on_init_size +=
static_cast<size_t>(last_run_size);
982 this->my_size = on_init_size;
986 using const_segment_facade_t =
987 segment_facade_impl<blocks_table_t, segment_traits_t, true>;
990 using segment_facade_t =
991 segment_facade_impl<blocks_table_t, segment_traits_t, false>;
997 sizeof(size_type) ==
sizeof(std::atomic<size_type>),
998 "std::atomic should have the same layout as underlying integral type");
1000 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
1001 VALGRIND_HG_DISABLE_CHECKING(&my_mask,
sizeof(my_mask));
1003 layout_features = {0, 0};
1005 PMEMoid oid = pmemobj_oid(
this);
1007 assert(!OID_IS_NULL(oid));
1009 my_pool_uuid = oid.pool_uuid_lo;
1011 pool_base pop = get_pool_base();
1013 for (size_type i = 0; i < segment_traits_t::embedded_segments;
1016 pmemobj_oid(my_embedded_segment +
1017 segment_traits_t::segment_base(i));
1018 segment_facade_t seg(my_table, i);
1019 mark_rehashed<false>(pop, seg);
1026 this->tls_ptr =
nullptr;
1037 auto pop = get_pool_base();
1039 if ((layout_features.compat & FEATURE_CONSISTENT_SIZE) &&
1042 delete_persistent<tls_t>(tls_ptr);
1054 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
1055 VALGRIND_HG_DISABLE_CHECKING(&my_size,
sizeof(my_size));
1056 VALGRIND_HG_DISABLE_CHECKING(&my_mask,
sizeof(my_mask));
1058 #if LIBPMEMOBJ_CPP_VG_PMEMCHECK_ENABLED
1059 VALGRIND_PMC_REMOVE_PMEM_MAPPING(&my_size,
sizeof(my_size));
1060 VALGRIND_PMC_REMOVE_PMEM_MAPPING(&my_mask,
sizeof(my_mask));
1063 hashcode_type m = embedded_buckets - 1;
1065 const_segment_facade_t segment(
1066 my_table, segment_traits_t::embedded_segments);
1068 while (segment.is_valid()) {
1069 m += segment.size();
1073 mask().store(m, std::memory_order_relaxed);
1079 template <
bool Flush = true>
1081 mark_rehashed(pool_base &pop, segment_facade_t &segment)
1083 for (size_type i = 0; i < segment.size(); ++i) {
1084 bucket *b = &(segment[i]);
1086 assert_not_locked<mutex_t, scoped_t>(b->mutex);
1088 b->set_rehashed(std::memory_order_relaxed);
1093 for (size_type i = 0; i < segment.size(); ++i) {
1094 bucket *b = &(segment[i]);
1095 pop.flush(b->rehashed);
1106 enable_segment(segment_index_t k,
bool is_initial =
false)
1110 pool_base pop = get_pool_base();
1113 if (k >= first_block) {
1114 segment_facade_t new_segment(my_table, k);
1116 sz = new_segment.size();
1117 if (!new_segment.is_valid())
1118 new_segment.enable(pop);
1121 mark_rehashed(pop, new_segment);
1128 assert(k == segment_traits_t::embedded_segments);
1130 for (segment_index_t i = k; i < first_block; ++i) {
1131 segment_facade_t new_segment(my_table, i);
1133 if (!new_segment.is_valid())
1134 new_segment.enable(pop);
1137 mark_rehashed(pop, new_segment);
1141 sz = segment_traits_t::segment_size(first_block);
1143 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
1144 ANNOTATE_HAPPENS_BEFORE(&my_mask);
1146 mask().store(sz - 1, std::memory_order_release);
1154 get_bucket(hashcode_type h)
const
1156 segment_index_t s = segment_traits_t::segment_index_of(h);
1158 h -= segment_traits_t::segment_base(s);
1160 const_segment_facade_t segment(my_table, s);
1162 assert(segment.is_valid());
1164 return &(segment[h]);
1171 check_mask_race(hashcode_type h, hashcode_type &m)
const
1173 hashcode_type m_now, m_old = m;
1175 m_now = mask().load(std::memory_order_acquire);
1176 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
1177 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
1181 return check_rehashing_collision(h, m_old, m = m_now);
1190 check_rehashing_collision(hashcode_type h, hashcode_type m_old,
1191 hashcode_type m)
const
1195 if ((h & m_old) != (h & m)) {
1200 for (++m_old; !(h & m_old); m_old <<= 1)
1203 m_old = (m_old << 1) - 1;
1205 assert((m_old & (m_old + 1)) == 0 && m_old <= m);
1208 bucket *b = get_bucket(h & m_old);
1209 return b->is_rehashed(std::memory_order_acquire);
1219 template <
typename Node,
typename... Args>
1221 insert_new_node_internal(bucket *b,
1222 detail::persistent_pool_ptr<Node> &new_node,
1225 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
1227 new_node = pmem::obj::make_persistent<Node>(
1228 b->node_list, std::forward<Args>(args)...);
1229 b->node_list = new_node;
1236 template <
typename Node,
typename... Args>
1238 insert_new_node(bucket *b, detail::persistent_pool_ptr<Node> &new_node,
1241 pool_base pop = get_pool_base();
1248 if (pmemobj_tx_stage() == TX_STAGE_WORK) {
1249 insert_new_node_internal(b, new_node,
1250 std::forward<Args>(args)...);
1251 this->on_init_size++;
1253 auto &size_diff = thread_size_diff();
1256 insert_new_node_internal(
1258 std::forward<Args>(args)...);
1264 return ++(this->my_size);
1272 check_growth(hashcode_type m, size_type sz)
1275 segment_index_t new_seg =
1276 static_cast<segment_index_t
>(detail::Log2(
1280 assert(segment_facade_t(my_table, new_seg - 1)
1283 std::unique_lock<segment_enable_mutex_t> lock(
1284 my_segment_enable_mutex, std::try_to_lock);
1287 if (mask().load(std::memory_order_relaxed) ==
1291 enable_segment(new_seg);
1305 reserve(size_type buckets)
1312 bool is_initial = this->size() == 0;
1314 for (size_type m = mask(); buckets > m; m = mask())
1316 segment_traits_t::segment_index_of(m + 1),
1325 internal_swap(hash_map_base<Key, T, mutex_t, scoped_t> &table)
1327 pool_base p = get_pool_base();
1329 transaction::manual tx(p);
1331 this->my_pool_uuid.swap(table.my_pool_uuid);
1342 this->mask() = table.mask().exchange(
1343 this->mask(), std::memory_order_relaxed);
1345 this->my_size = table.my_size.exchange(
1346 this->my_size, std::memory_order_relaxed);
1349 std::swap(this->tls_ptr, table.tls_ptr);
1351 for (size_type i = 0; i < embedded_buckets; ++i)
1352 this->my_embedded_segment[i].node_list.swap(
1353 table.my_embedded_segment[i].node_list);
1355 for (size_type i = segment_traits_t::embedded_segments;
1356 i < block_table_size; ++i)
1357 this->my_table[i].
swap(table.my_table[i]);
1371 pmemobj_pool_by_oid(PMEMoid{my_pool_uuid, 0});
1373 return pool_base(pop);
1382 template <
typename Container,
bool is_const>
1383 class hash_map_iterator {
1385 using iterator_category = std::forward_iterator_tag;
1386 using difference_type = ptrdiff_t;
1387 using map_type = Container;
1388 using value_type =
typename map_type::value_type;
1389 using node =
typename map_type::node;
1390 using bucket =
typename map_type::bucket;
1391 using map_ptr =
typename std::conditional<is_const,
const map_type *,
1394 typename std::conditional<is_const,
1395 typename map_type::const_reference,
1396 typename map_type::reference>::type;
1398 typename std::conditional<is_const,
1399 typename map_type::const_pointer,
1400 typename map_type::pointer>::type;
1402 template <
typename C,
bool M,
bool U>
1403 friend bool operator==(
const hash_map_iterator<C, M> &i,
1404 const hash_map_iterator<C, U> &j);
1406 template <
typename C,
bool M,
bool U>
1407 friend bool operator!=(
const hash_map_iterator<C, M> &i,
1408 const hash_map_iterator<C, U> &j);
1410 friend class hash_map_iterator<map_type, true>;
1412 #if !defined(_MSC_VER) || defined(__INTEL_COMPILER)
1414 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
1415 typename MutexType,
typename ScopedLockType>
1416 friend class ::pmem::obj::concurrent_hash_map;
1420 hash_map_iterator(map_ptr map,
size_t index)
1421 : my_map(map), my_index(index), my_bucket(nullptr), my_node(nullptr)
1423 if (my_index <= my_map->mask()) {
1424 bucket_accessor acc(my_map, my_index);
1425 my_bucket = acc.get();
1426 my_node =
static_cast<node *
>(
1427 my_bucket->node_list.get(my_map->my_pool_uuid));
1430 advance_to_next_bucket();
1437 hash_map_iterator() =
default;
1440 hash_map_iterator(
const hash_map_iterator &other)
1441 : my_map(other.my_map),
1442 my_index(other.my_index),
1443 my_bucket(other.my_bucket),
1444 my_node(other.my_node)
1449 template <
typename U = void,
1450 typename =
typename std::enable_if<is_const, U>::type>
1451 hash_map_iterator(
const hash_map_iterator<map_type, false> &other)
1452 : my_map(other.my_map),
1453 my_index(other.my_index),
1454 my_bucket(other.my_bucket),
1455 my_node(other.my_node)
1459 hash_map_iterator &operator=(
const hash_map_iterator &it) =
default;
1462 reference operator*()
const
1465 return my_node->item;
1469 pointer operator->()
const
1471 return &operator*();
1478 my_node =
static_cast<node *
>(
1479 my_node->next.get((my_map->my_pool_uuid)));
1482 advance_to_next_bucket();
1491 hash_map_iterator old(*
this);
1498 map_ptr my_map =
nullptr;
1501 size_t my_index = 0;
1504 bucket *my_bucket =
nullptr;
1507 node *my_node =
nullptr;
1509 class bucket_accessor {
1511 bucket_accessor(map_ptr m,
size_t index)
1513 my_bucket = m->get_bucket(index);
1527 advance_to_next_bucket()
1529 size_t k = my_index + 1;
1533 while (k <= my_map->mask()) {
1534 bucket_accessor acc(my_map, k);
1535 my_bucket = acc.get();
1537 if (my_bucket->node_list) {
1538 my_node =
static_cast<node *
>(
1539 my_bucket->node_list.get(
1540 my_map->my_pool_uuid));
1556 template <
typename Container,
bool M,
bool U>
1558 operator==(
const hash_map_iterator<Container, M> &i,
1559 const hash_map_iterator<Container, U> &j)
1561 return i.my_node == j.my_node && i.my_map == j.my_map;
1564 template <
typename Container,
bool M,
bool U>
1566 operator!=(
const hash_map_iterator<Container, M> &i,
1567 const hash_map_iterator<Container, U> &j)
1569 return i.my_node != j.my_node || i.my_map != j.my_map;
1620 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
1621 typename MutexType,
typename ScopedLockType>
1623 :
protected concurrent_hash_map_internal::hash_map_base<Key, T, MutexType,
1625 template <
typename Container,
bool is_const>
1626 friend class concurrent_hash_map_internal::hash_map_iterator;
1629 using size_type =
typename concurrent_hash_map_internal::hash_map_base<
1630 Key, T, MutexType, ScopedLockType>::size_type;
1631 using hashcode_type =
1632 typename concurrent_hash_map_internal::hash_map_base<
1633 Key, T, MutexType, ScopedLockType>::hashcode_type;
1634 using key_type = Key;
1635 using mapped_type = T;
1636 using value_type =
typename concurrent_hash_map_internal::hash_map_base<
1637 Key, T, MutexType, ScopedLockType>::node::value_type;
1638 using difference_type = ptrdiff_t;
1639 using pointer = value_type *;
1640 using const_pointer =
const value_type *;
1641 using reference = value_type &;
1642 using const_reference =
const value_type &;
1643 using iterator = concurrent_hash_map_internal::hash_map_iterator<
1645 using const_iterator = concurrent_hash_map_internal::hash_map_iterator<
1647 using hasher = Hash;
1648 using key_equal =
typename concurrent_hash_map_internal::key_equal_type<
1649 Hash, KeyEqual>::type;
1652 using mutex_t = MutexType;
1653 using scoped_t = ScopedLockType;
1657 using hash_map_base =
1658 concurrent_hash_map_internal::hash_map_base<Key, T, mutex_t,
1660 using hash_map_base::calculate_mask;
1661 using hash_map_base::check_growth;
1662 using hash_map_base::check_mask_race;
1663 using hash_map_base::embedded_buckets;
1664 using hash_map_base::FEATURE_CONSISTENT_SIZE;
1665 using hash_map_base::get_bucket;
1666 using hash_map_base::get_pool_base;
1667 using hash_map_base::header_features;
1668 using hash_map_base::insert_new_node;
1669 using hash_map_base::internal_swap;
1670 using hash_map_base::layout_features;
1671 using hash_map_base::mask;
1672 using hash_map_base::reserve;
1673 using tls_t =
typename hash_map_base::tls_t;
1674 using node =
typename hash_map_base::node;
1675 using node_mutex_t =
typename node::mutex_t;
1676 using node_ptr_t =
typename hash_map_base::node_ptr_t;
1677 using bucket =
typename hash_map_base::bucket;
1678 using bucket_lock_type =
typename bucket::scoped_t;
1679 using segment_index_t =
typename hash_map_base::segment_index_t;
1680 using segment_traits_t =
typename hash_map_base::segment_traits_t;
1681 using segment_facade_t =
typename hash_map_base::segment_facade_t;
1682 using scoped_lock_traits_type =
1683 concurrent_hash_map_internal::scoped_lock_traits<scoped_t>;
1686 using persistent_node_ptr_t = detail::persistent_pool_ptr<node>;
1689 delete_node(
const node_ptr_t &n)
1691 delete_persistent<node>(
1692 detail::static_persistent_pool_pointer_cast<node>(n)
1693 .get_persistent_ptr(this->my_pool_uuid));
1696 template <
typename K>
1697 persistent_node_ptr_t
1698 search_bucket(
const K &key, bucket *b)
const
1700 assert(b->is_rehashed(std::memory_order_relaxed));
1702 persistent_node_ptr_t n =
1703 detail::static_persistent_pool_pointer_cast<node>(
1708 n.get(this->my_pool_uuid)->item.first)) {
1709 n = detail::static_persistent_pool_pointer_cast<node>(
1710 n.get(this->my_pool_uuid)->next);
1726 bucket_lock_type::mutex = b.bucket_lock_type::mutex;
1727 bucket_lock_type::is_writer =
1728 b.bucket_lock_type::is_writer;
1730 b.bucket_lock_type::mutex =
nullptr;
1731 b.bucket_lock_type::is_writer =
false;
1735 const hashcode_type h,
bool writer =
false)
1751 bool writer =
false)
1753 my_b = base->get_bucket(h);
1755 if (my_b->is_rehashed(std::memory_order_acquire) ==
1757 bucket_lock_type::try_acquire(this->my_b->mutex,
1759 if (my_b->is_rehashed(
1760 std::memory_order_relaxed) ==
1763 base->rehash_bucket<
false>(my_b, h);
1766 bucket_lock_type::acquire(my_b->mutex, writer);
1769 assert(my_b->is_rehashed(std::memory_order_relaxed));
1778 return bucket_lock_type::is_writer;
1809 const hashcode_type h,
1810 bool writer =
false)
1812 acquire(base, h, writer);
1820 bool writer =
false)
1822 my_b = base->get_bucket(h);
1824 if (my_b->is_rehashed(std::memory_order_relaxed) ==
1827 base->rehash_bucket<
true>(my_b, h);
1830 assert(my_b->is_rehashed(std::memory_order_relaxed));
1866 get_hash_code(node_ptr_t &n)
1869 detail::static_persistent_pool_pointer_cast<node>(n)(
1874 template <
bool serial>
1876 rehash_bucket(bucket *b_new,
const hashcode_type h)
1878 using accessor_type =
typename std::conditional<
1879 serial, serial_bucket_accessor, bucket_accessor>::type;
1881 using scoped_lock_traits_type =
1882 concurrent_hash_map_internal::scoped_lock_traits<
1888 pool_base pop = get_pool_base();
1889 node_ptr_t *p_new = &(b_new->node_list);
1893 if (*p_new !=
nullptr) {
1894 assert(!b_new->is_rehashed(std::memory_order_relaxed));
1896 b_new->set_rehashed(std::memory_order_relaxed);
1897 pop.persist(b_new->rehashed);
1903 hashcode_type mask = (1u << detail::Log2(h)) - 1;
1904 assert((h & mask) < h);
1905 accessor_type b_old(
1907 scoped_lock_traits_type::initial_rw_state(
true));
1911 mask = (mask << 1) | 1;
1912 assert((mask & (mask + 1)) == 0 && (h & mask) == h);
1915 for (node_ptr_t *p_old = &(b_old->node_list),
1918 hashcode_type c = get_hash_code(n);
1920 hashcode_type bmask = h & (mask >> 1);
1924 : (1u << (detail::Log2(bmask) + 1)) - 1;
1926 assert((c & bmask) == (h & bmask));
1929 if ((c & mask) == h) {
1930 if (!b_old.is_writer() &&
1931 !scoped_lock_traits_type::
1932 upgrade_to_writer(b_old)) {
1942 *p_old = n(this->my_pool_uuid)->next;
1944 p_new = &(n(this->my_pool_uuid)->next);
1947 p_old = &(n(this->my_pool_uuid)->next);
1955 b_new->set_rehashed(std::memory_order_release);
1956 pop.persist(b_new->rehashed);
1960 check_incompat_features()
1962 if (layout_features.incompat != header_features().incompat)
1964 "Incompat flags mismatch, for more details go to: https://pmem.io/pmdk/cpp_obj/ \n");
1966 if ((layout_features.compat & FEATURE_CONSISTENT_SIZE) &&
1967 this->value_size !=
sizeof(value_type))
1969 "Size of value_type is different than the one stored in the pool \n");
1978 :
protected node::scoped_t {
1983 using node::scoped_t::try_acquire;
1990 const typename concurrent_hash_map::value_type;
2011 concurrent_hash_map_internal::check_outside_tx();
2014 node::scoped_t::release();
2026 return my_node->item;
2044 concurrent_hash_map_internal::check_outside_tx();
2059 hashcode_type my_hash;
2074 assert(this->my_node);
2076 return this->my_node->item;
2112 reserve(table.
size());
2130 template <
typename I>
2135 reserve(
static_cast<size_type
>(std::distance(first, last)));
2163 check_incompat_features();
2171 if (!(layout_features.compat & FEATURE_CONSISTENT_SIZE)) {
2173 std::distance(this->
begin(), this->
end());
2174 assert(actual_size >= 0);
2176 this->my_size =
static_cast<size_t>(actual_size);
2178 auto pop = get_pool_base();
2180 this->tls_ptr = make_persistent<tls_t>();
2181 this->on_init_size =
2182 static_cast<size_t>(actual_size);
2183 this->value_size =
sizeof(value_type);
2185 layout_features.compat |=
2186 FEATURE_CONSISTENT_SIZE;
2189 assert(this->tls_ptr !=
nullptr);
2190 this->tls_restore();
2193 assert(this->
size() ==
2194 size_type(std::distance(this->
begin(), this->
end())));
2198 "runtime_initialize(bool) is now deprecated, use runtime_initialize(void)")]]
void
2201 check_incompat_features();
2205 if (!graceful_shutdown) {
2207 std::distance(this->
begin(), this->
end());
2208 assert(actual_size >= 0);
2209 this->my_size =
static_cast<size_type
>(actual_size);
2211 assert(this->
size() ==
2212 size_type(std::distance(this->
begin(),
2228 concurrent_hash_map &
2231 if (
this != &table) {
2270 void rehash(size_type n = 0);
2298 auto pop = get_pool_base();
2336 return iterator(
this, 0);
2346 return iterator(
this, mask() + 1);
2356 return const_iterator(
this, 0);
2366 return const_iterator(
this, mask() + 1);
2375 return hash_map_base::size();
2384 return this->
size() == 0;
2393 return (~size_type(0)) /
sizeof(node);
2422 concurrent_hash_map_internal::check_outside_tx();
2425 key,
nullptr,
false);
2439 template <
typename K,
2440 typename =
typename std::enable_if<
2441 concurrent_hash_map_internal::
2442 has_transparent_key_equal<hasher>::value,
2447 concurrent_hash_map_internal::check_outside_tx();
2450 key,
nullptr,
false);
2462 concurrent_hash_map_internal::check_outside_tx();
2467 key, &result,
false);
2483 template <
typename K,
2484 typename =
typename std::enable_if<
2485 concurrent_hash_map_internal::
2486 has_transparent_key_equal<hasher>::value,
2491 concurrent_hash_map_internal::check_outside_tx();
2496 key, &result,
false);
2508 concurrent_hash_map_internal::check_outside_tx();
2512 return internal_find(key, &result,
true);
2528 template <
typename K,
2529 typename =
typename std::enable_if<
2530 concurrent_hash_map_internal::
2531 has_transparent_key_equal<hasher>::value,
2536 concurrent_hash_map_internal::check_outside_tx();
2540 return internal_find(key, &result,
true);
2552 concurrent_hash_map_internal::check_outside_tx();
2556 return internal_insert(key, &result,
false, key);
2569 concurrent_hash_map_internal::check_outside_tx();
2573 return internal_insert(key, &result,
true, key);
2586 concurrent_hash_map_internal::check_outside_tx();
2590 return internal_insert(value.first, &result,
false, value);
2603 concurrent_hash_map_internal::check_outside_tx();
2607 return internal_insert(value.first, &result,
true, value);
2619 concurrent_hash_map_internal::check_outside_tx();
2621 return internal_insert(value.first,
nullptr,
false, value);
2634 concurrent_hash_map_internal::check_outside_tx();
2638 return internal_insert(value.first, &result,
false,
2652 concurrent_hash_map_internal::check_outside_tx();
2656 return internal_insert(value.first, &result,
true,
2669 concurrent_hash_map_internal::check_outside_tx();
2671 return internal_insert(value.first,
nullptr,
false,
2680 template <
typename I>
2684 concurrent_hash_map_internal::check_outside_tx();
2686 for (; first != last; ++first)
2698 concurrent_hash_map_internal::check_outside_tx();
2700 insert(il.begin(), il.end());
2711 template <
typename M>
2715 concurrent_hash_map_internal::check_outside_tx();
2718 auto result = internal_insert(key, &acc,
true, key,
2719 std::forward<M>(obj));
2724 acc->second = std::forward<M>(obj);
2739 template <
typename M>
2743 concurrent_hash_map_internal::check_outside_tx();
2746 auto result = internal_insert(key, &acc,
true, std::move(key),
2747 std::forward<M>(obj));
2752 acc->second = std::forward<M>(obj);
2768 typename K,
typename M,
2769 typename =
typename std::enable_if<
2770 concurrent_hash_map_internal::has_transparent_key_equal<
2772 std::is_constructible<key_type, K>::value,
2777 concurrent_hash_map_internal::check_outside_tx();
2781 internal_insert(key, &acc,
true, std::forward<K>(key),
2782 std::forward<M>(obj));
2787 acc->second = std::forward<M>(obj);
2805 concurrent_hash_map_internal::check_outside_tx();
2807 return internal_erase(key);
2829 defragment(
double start_percent = 0,
double amount_percent = 100)
2831 double end_percent = start_percent + amount_percent;
2832 if (start_percent < 0 || start_percent >= 100 ||
2833 end_percent < 0 || end_percent > 100 ||
2834 start_percent >= end_percent) {
2835 throw std::range_error(
"incorrect range");
2838 size_t max_index = mask().load(std::memory_order_acquire);
2839 size_t start_index =
2840 static_cast<size_t>((start_percent * max_index) / 100);
2842 static_cast<size_t>((end_percent * max_index) / 100);
2846 end_index = (std::min)(end_index, max_index);
2848 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
2849 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
2862 for (
size_t i = end_index + 1; i >= start_index + 1; i--) {
2874 return my_defrag.
run();
2891 template <
typename K,
2892 typename =
typename std::enable_if<
2893 concurrent_hash_map_internal::
2894 has_transparent_key_equal<hasher>::value,
2899 concurrent_hash_map_internal::check_outside_tx();
2901 return internal_erase(key);
2911 bool try_acquire_item(const_accessor *result, node_mutex_t &
mutex,
2920 using mutex_t = MutexType;
2926 vec.emplace_back(base, h,
true );
2927 bucket *b = vec.back().get();
2929 auto node_ptr =
static_cast<node *
>(
2930 b->node_list.get(base->my_pool_uuid));
2934 if (!base->try_acquire_item(&ca,
2942 static_cast<node *
>(node_ptr->next.get(
2943 (base->my_pool_uuid)));
2950 std::vector<bucket_accessor> vec;
2953 template <
typename K>
2954 bool internal_find(
const K &key, const_accessor *result,
bool write);
2956 template <
typename K,
typename... Args>
2957 bool internal_insert(
const K &key, const_accessor *result,
bool write,
2961 template <
bool Bucket_rw_lock,
typename K>
2962 persistent_node_ptr_t
2963 get_node(
const K &key, bucket_accessor &b)
2966 auto n = search_bucket(key, b.get());
2969 if (Bucket_rw_lock && !b.is_writer() &&
2970 !scoped_lock_traits_type::upgrade_to_writer(b)) {
2974 n = search_bucket(key, b.get());
2977 scoped_lock_traits_type::
2978 downgrade_to_reader(b);
2987 template <
typename K>
2988 bool internal_erase(
const K &key);
2990 void clear_segment(segment_index_t s);
2997 template <
typename I>
3007 auto node_ptr =
static_cast<node *
>(
3008 b->node_list.get(this->my_pool_uuid));
3019 node_ptr =
static_cast<node *
>(
3020 node_ptr->next.get((this->my_pool_uuid)));
3025 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3026 typename MutexType,
typename ScopedLockType>
3028 concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3029 ScopedLockType>::try_acquire_item(const_accessor *result,
3030 node_mutex_t &mutex,
3034 if (!result->try_acquire(mutex, write)) {
3035 for (detail::atomic_backoff backoff(
true);;) {
3036 if (result->try_acquire(mutex, write))
3039 if (!backoff.bounded_pause())
3047 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3048 typename MutexType,
typename ScopedLockType>
3049 template <
typename K>
3051 concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3052 ScopedLockType>::internal_find(
const K &key,
3053 const_accessor *result,
3056 assert(!result || !result->my_node);
3058 hashcode_type m = mask().load(std::memory_order_acquire);
3059 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
3060 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
3063 assert((m & (m + 1)) == 0);
3065 hashcode_type
const h = hasher{}(key);
3067 persistent_node_ptr_t node;
3073 scoped_lock_traits_type::initial_rw_state(
false));
3074 node = get_node<false>(key, b);
3078 if (check_mask_race(h, m)) {
3089 result, node.get(this->my_pool_uuid)->mutex, write))
3096 std::this_thread::yield();
3098 m = mask().load(std::memory_order_acquire);
3099 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
3100 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
3105 result->my_node = node.get_persistent_ptr(this->my_pool_uuid);
3106 result->my_hash = h;
3112 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3113 typename MutexType,
typename ScopedLockType>
3114 template <
typename K,
typename... Args>
3116 concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3117 ScopedLockType>::internal_insert(
const K &key,
3118 const_accessor *result,
3122 assert(!result || !result->my_node);
3124 hashcode_type m = mask().load(std::memory_order_acquire);
3125 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
3126 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
3129 assert((m & (m + 1)) == 0);
3131 hashcode_type
const h = hasher{}(key);
3133 persistent_node_ptr_t node;
3134 size_t new_size = 0;
3135 bool inserted =
false;
3141 scoped_lock_traits_type::initial_rw_state(
true));
3142 node = get_node<true>(key, b);
3146 if (check_mask_race(h, m)) {
3152 new_size = insert_new_node(b.get(), node,
3153 std::forward<Args>(args)...);
3160 result, node.get(this->my_pool_uuid)->mutex, write))
3167 std::this_thread::yield();
3169 m = mask().load(std::memory_order_acquire);
3170 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
3171 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
3176 result->my_node = node.get_persistent_ptr(this->my_pool_uuid);
3177 result->my_hash = h;
3180 check_growth(m, new_size);
3185 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3186 typename MutexType,
typename ScopedLockType>
3187 template <
typename K>
3189 concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3190 ScopedLockType>::internal_erase(
const K &key)
3193 hashcode_type
const h = hasher{}(key);
3194 hashcode_type m = mask().load(std::memory_order_acquire);
3195 #if LIBPMEMOBJ_CPP_VG_HELGRIND_ENABLED
3196 ANNOTATE_HAPPENS_AFTER(&(this->my_mask));
3199 pool_base pop = get_pool_base();
3204 bucket_accessor b(
this, h & m,
3205 scoped_lock_traits_type::initial_rw_state(
true));
3208 node_ptr_t *p = &b->node_list;
3213 detail::static_persistent_pool_pointer_cast<node>(
3214 n)(this->my_pool_uuid)
3216 p = &n(this->my_pool_uuid)->next;
3222 if (check_mask_race(h, m))
3226 }
else if (!b.is_writer() &&
3227 !scoped_lock_traits_type::upgrade_to_writer(b)) {
3228 if (check_mask_race(h, m))
3234 persistent_ptr<node> del = n(this->my_pool_uuid);
3242 if (!try_acquire_item(&acc, del->mutex,
true)) {
3246 std::this_thread::yield();
3248 m = mask().load(std::memory_order_acquire);
3254 assert(pmemobj_tx_stage() == TX_STAGE_NONE);
3256 auto &size_diff = this->thread_size_diff();
3273 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3274 typename MutexType,
typename ScopedLockType>
3279 internal_swap(table);
3282 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3283 typename MutexType,
typename ScopedLockType>
3288 concurrent_hash_map_internal::check_outside_tx();
3291 hashcode_type m = mask();
3295 hashcode_type b = (m + 1) >> 1;
3298 assert((b & (b - 1)) == 0);
3300 for (; b <= m; ++b) {
3301 bucket *bp = get_bucket(b);
3303 concurrent_hash_map_internal::assert_not_locked<mutex_t,
3307 if (bp->is_rehashed(std::memory_order_relaxed) ==
false)
3308 rehash_bucket<true>(bp, b);
3312 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3313 typename MutexType,
typename ScopedLockType>
3317 hashcode_type m = mask();
3319 assert((m & (m + 1)) == 0);
3323 for (segment_index_t b = 0; b <= m; ++b) {
3324 bucket *bp = get_bucket(b);
3325 concurrent_hash_map_internal::assert_not_locked<mutex_t,
3336 assert(this->tls_ptr !=
nullptr);
3337 this->tls_ptr->clear();
3339 this->on_init_size = 0;
3341 segment_index_t s = segment_traits_t::segment_index_of(m);
3343 assert(s + 1 == this->block_table_size ||
3344 !segment_facade_t(this->my_table, s + 1).is_valid());
3359 mask().store(embedded_buckets - 1, std::memory_order_relaxed);
3366 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3367 typename MutexType,
typename ScopedLockType>
3370 ScopedLockType>::clear_segment(segment_index_t s)
3372 segment_facade_t segment(this->my_table, s);
3374 assert(segment.is_valid());
3376 size_type sz = segment.size();
3377 for (segment_index_t i = 0; i < sz; ++i) {
3378 for (node_ptr_t n = segment[i].node_list; n;
3379 n = segment[i].node_list) {
3380 segment[i].node_list = n(this->my_pool_uuid)->next;
3385 if (s >= segment_traits_t::embedded_segments)
3389 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3390 typename MutexType,
typename ScopedLockType>
3395 auto pop = get_pool_base();
3397 reserve(source.
size());
3398 internal_copy(source.
begin(), source.
end());
3401 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3402 typename MutexType,
typename ScopedLockType>
3403 template <
typename I>
3406 ScopedLockType>::internal_copy(I first, I last)
3408 hashcode_type m = mask();
3410 for (; first != last; ++first) {
3411 hashcode_type h = hasher{}(first->first);
3412 bucket *b = get_bucket(h & m);
3414 assert(b->is_rehashed(std::memory_order_relaxed));
3416 detail::persistent_pool_ptr<node> p;
3417 insert_new_node(b, p, *first);
3421 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3422 typename MutexType,
typename ScopedLockType>
3424 operator==(
const concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3426 const concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3429 if (a.size() != b.size())
3432 typename concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3433 ScopedLockType>::const_iterator
3437 typename concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3438 ScopedLockType>::const_iterator j,
3441 for (; i != i_end; ++i) {
3442 j = b.equal_range(i->first).first;
3444 if (j == j_end || !(i->second == j->second))
3451 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3452 typename MutexType,
typename ScopedLockType>
3454 operator!=(
const concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3456 const concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType,
3462 template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
3463 typename MutexType,
typename ScopedLockType>
3465 swap(concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType, ScopedLockType> &a,
3466 concurrent_hash_map<Key, T, Hash, KeyEqual, MutexType, ScopedLockType> &b)