24#ifndef TSL_BHOPSCOTCH_MAP_H
25#define TSL_BHOPSCOTCH_MAP_H
30#include <initializer_list>
55 template <
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
56 class Compare = std::less<Key>,
57 class Allocator = std::allocator<std::pair<const Key, T>>,
58 unsigned int NeighborhoodSize = 62,
bool StoreHash = false,
59 class GrowthPolicy = tsl::hh::power_of_two_growth_policy<2>>
73 return key_value.first;
86 return key_value.second;
98 KeyEqual, Allocator, NeighborhoodSize, StoreHash,
124 const KeyEqual &equal = KeyEqual(),
125 const Allocator &alloc = Allocator(),
const Compare &comp = Compare())
145 template <
class InputIt>
148 const Hash &hash = Hash(),
const KeyEqual &equal = KeyEqual(),
149 const Allocator &alloc = Allocator())
155 template <
class InputIt>
161 template <
class InputIt>
163 const Allocator &alloc)
170 const Hash &hash = Hash(),
const KeyEqual &equal = KeyEqual(),
171 const Allocator &alloc = Allocator())
177 const Allocator &alloc)
183 const Allocator &alloc)
225 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
227 std::pair<iterator, bool>
insert(P &&value)
239 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
243 return m_ht.
insert(hint, std::forward<P>(value));
251 template <
class InputIt>
void insert(InputIt first, InputIt last) {
m_ht.
insert(first, last); }
253 void insert(std::initializer_list<value_type> ilist)
285 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&...args)
302 template <
class... Args>
313 template <
class... Args>
321 return m_ht.
try_emplace(hint, std::move(k), std::forward<Args>(args)...);
336 return m_ht.
erase(key, precalculated_hash);
344 template <
class K,
class KE = KeyEqual,
class CP = Compare,
345 typename std::enable_if<has_is_transparent<KE>::value &&
346 has_is_transparent<CP>::value>::type * =
nullptr>
357 template <
class K,
class KE = KeyEqual,
class CP = Compare,
358 typename std::enable_if<has_is_transparent<KE>::value &&
359 has_is_transparent<CP>::value>::type * =
nullptr>
362 return m_ht.
erase(key, precalculated_hash);
377 T &
at(
const Key &key, std::size_t precalculated_hash)
379 return m_ht.
at(key, precalculated_hash);
382 const T &
at(
const Key &key)
const {
return m_ht.
at(key); }
386 const T &
at(
const Key &key, std::size_t precalculated_hash)
const
388 return m_ht.
at(key, precalculated_hash);
396 template <
class K,
class KE = KeyEqual,
class CP = Compare,
397 typename std::enable_if<has_is_transparent<KE>::value &&
398 has_is_transparent<CP>::value>::type * =
nullptr>
409 template <
class K,
class KE = KeyEqual,
class CP = Compare,
410 typename std::enable_if<has_is_transparent<KE>::value &&
411 has_is_transparent<CP>::value>::type * =
nullptr>
412 T &
at(
const K &key, std::size_t precalculated_hash)
414 return m_ht.
at(key, precalculated_hash);
419 template <
class K,
class KE = KeyEqual,
class CP = Compare,
420 typename std::enable_if<has_is_transparent<KE>::value &&
421 has_is_transparent<CP>::value>::type * =
nullptr>
422 const T &
at(
const K &key)
const
429 template <
class K,
class KE = KeyEqual,
class CP = Compare,
430 typename std::enable_if<has_is_transparent<KE>::value &&
431 has_is_transparent<CP>::value>::type * =
nullptr>
432 const T &
at(
const K &key, std::size_t precalculated_hash)
const
434 return m_ht.
at(key, precalculated_hash);
449 return m_ht.
count(key, precalculated_hash);
457 template <
class K,
class KE = KeyEqual,
class CP = Compare,
458 typename std::enable_if<has_is_transparent<KE>::value &&
459 has_is_transparent<CP>::value>::type * =
nullptr>
470 template <
class K,
class KE = KeyEqual,
class CP = Compare,
471 typename std::enable_if<has_is_transparent<KE>::value &&
472 has_is_transparent<CP>::value>::type * =
nullptr>
475 return m_ht.
count(key, precalculated_hash);
487 return m_ht.
find(key, precalculated_hash);
496 return m_ht.
find(key, precalculated_hash);
504 template <
class K,
class KE = KeyEqual,
class CP = Compare,
505 typename std::enable_if<has_is_transparent<KE>::value &&
506 has_is_transparent<CP>::value>::type * =
nullptr>
517 template <
class K,
class KE = KeyEqual,
class CP = Compare,
518 typename std::enable_if<has_is_transparent<KE>::value &&
519 has_is_transparent<CP>::value>::type * =
nullptr>
522 return m_ht.
find(key, precalculated_hash);
527 template <
class K,
class KE = KeyEqual,
class CP = Compare,
528 typename std::enable_if<has_is_transparent<KE>::value &&
529 has_is_transparent<CP>::value>::type * =
nullptr>
537 template <
class K,
class KE = KeyEqual,
class CP = Compare,
538 typename std::enable_if<has_is_transparent<KE>::value &&
539 has_is_transparent<CP>::value>::type * =
nullptr>
542 return m_ht.
find(key, precalculated_hash);
552 bool contains(
const Key &key, std::size_t precalculated_hash)
const
562 template <
class K,
class KE = KeyEqual,
563 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
574 template <
class K,
class KE = KeyEqual,
575 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
576 bool contains(
const K &key, std::size_t precalculated_hash)
const
588 std::pair<iterator, iterator>
equal_range(
const Key &key, std::size_t precalculated_hash)
593 std::pair<const_iterator, const_iterator>
equal_range(
const Key &key)
const
600 std::pair<const_iterator, const_iterator>
equal_range(
const Key &key,
601 std::size_t precalculated_hash)
const
611 template <
class K,
class KE = KeyEqual,
class CP = Compare,
612 typename std::enable_if<has_is_transparent<KE>::value &&
613 has_is_transparent<CP>::value>::type * =
nullptr>
624 template <
class K,
class KE = KeyEqual,
class CP = Compare,
625 typename std::enable_if<has_is_transparent<KE>::value &&
626 has_is_transparent<CP>::value>::type * =
nullptr>
627 std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t precalculated_hash)
634 template <
class K,
class KE = KeyEqual,
class CP = Compare,
635 typename std::enable_if<has_is_transparent<KE>::value &&
636 has_is_transparent<CP>::value>::type * =
nullptr>
637 std::pair<const_iterator, const_iterator>
equal_range(
const K &key)
const
644 template <
class K,
class KE = KeyEqual,
class CP = Compare,
645 typename std::enable_if<has_is_transparent<KE>::value &&
646 has_is_transparent<CP>::value>::type * =
nullptr>
647 std::pair<const_iterator, const_iterator>
equal_range(
const K &key,
648 std::size_t precalculated_hash)
const
693 for (
const auto &element_lhs : lhs) {
694 const auto it_element_rhs = rhs.
find(element_lhs.first);
695 if (it_element_rhs == rhs.
cend() || element_lhs.second != it_element_rhs->second) {
718 template <
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
719 class Compare = std::less<Key>,
720 class Allocator = std::allocator<std::pair<const Key, T>>,
721 unsigned int NeighborhoodSize = 62,
bool StoreHash = false>
723 bhopscotch_map<Key, T, Hash, KeyEqual, Compare, Allocator, NeighborhoodSize, StoreHash,
Definition bhopscotch_map.h:67
Key key_type
Definition bhopscotch_map.h:69
const key_type & operator()(std::pair< const Key, T > &key_value)
Definition bhopscotch_map.h:76
const key_type & operator()(const std::pair< const Key, T > &key_value) const
Definition bhopscotch_map.h:71
Definition bhopscotch_map.h:80
const value_type & operator()(const std::pair< const Key, T > &key_value) const
Definition bhopscotch_map.h:84
T value_type
Definition bhopscotch_map.h:82
value_type & operator()(std::pair< const Key, T > &key_value)
Definition bhopscotch_map.h:89
Definition bhopscotch_map.h:61
friend void swap(bhopscotch_map &lhs, bhopscotch_map &rhs)
Definition bhopscotch_map.h:708
iterator try_emplace(const_iterator hint, const key_type &k, Args &&...args)
Definition bhopscotch_map.h:314
size_type max_size() const noexcept
Definition bhopscotch_map.h:216
iterator try_emplace(const_iterator hint, key_type &&k, Args &&...args)
Definition bhopscotch_map.h:319
iterator end() noexcept
Definition bhopscotch_map.h:207
typename ht::value_type value_type
Definition bhopscotch_map.h:104
T & operator[](Key &&key)
Definition bhopscotch_map.h:438
bhopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition bhopscotch_map.h:176
const T & at(const K &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:432
iterator find(const K &key)
Definition bhopscotch_map.h:507
size_type overflow_size() const noexcept
Definition bhopscotch_map.h:685
bool contains(const Key &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:552
typename ht::const_reference const_reference
Definition bhopscotch_map.h:112
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:334
iterator begin() noexcept
Definition bhopscotch_map.h:203
T & at(const Key &key)
Definition bhopscotch_map.h:370
typename ht::const_pointer const_pointer
Definition bhopscotch_map.h:114
iterator find(const Key &key)
Definition bhopscotch_map.h:478
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:600
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:540
std::pair< iterator, bool > insert(P &&value)
Definition bhopscotch_map.h:227
key_equal key_eq() const
Definition bhopscotch_map.h:673
typename ht::key_type key_type
Definition bhopscotch_map.h:102
bhopscotch_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition bhopscotch_map.h:135
bhopscotch_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator(), const Compare &comp=Compare())
Definition bhopscotch_map.h:123
allocator_type get_allocator() const
Definition bhopscotch_map.h:198
iterator insert(const_iterator hint, P &&value)
Definition bhopscotch_map.h:241
const T & at(const K &key) const
Definition bhopscotch_map.h:422
size_type count(const Key &key) const
Definition bhopscotch_map.h:440
typename ht::const_iterator const_iterator
Definition bhopscotch_map.h:116
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition bhopscotch_map.h:637
size_type size() const noexcept
Definition bhopscotch_map.h:215
bhopscotch_map(size_type bucket_count, const Allocator &alloc)
Definition bhopscotch_map.h:130
size_type erase(const key_type &key)
Definition bhopscotch_map.h:327
void swap(bhopscotch_map &other)
Definition bhopscotch_map.h:365
bool contains(const Key &key) const
Definition bhopscotch_map.h:545
bhopscotch_map()
Definition bhopscotch_map.h:121
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition bhopscotch_map.h:268
Compare key_compare
Definition bhopscotch_map.h:109
key_compare key_comp() const
Definition bhopscotch_map.h:674
const_iterator begin() const noexcept
Definition bhopscotch_map.h:204
iterator emplace_hint(const_iterator hint, Args &&...args)
Definition bhopscotch_map.h:297
iterator insert(const_iterator hint, value_type &&value)
Definition bhopscotch_map.h:246
void clear() noexcept
Definition bhopscotch_map.h:221
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:647
bhopscotch_map & operator=(std::initializer_list< value_type > ilist)
Definition bhopscotch_map.h:188
ht m_ht
Definition bhopscotch_map.h:711
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition bhopscotch_map.h:593
friend bool operator==(const bhopscotch_map &lhs, const bhopscotch_map &rhs)
Definition bhopscotch_map.h:687
friend bool operator!=(const bhopscotch_map &lhs, const bhopscotch_map &rhs)
Definition bhopscotch_map.h:703
iterator insert(const_iterator hint, const value_type &value)
Definition bhopscotch_map.h:234
iterator erase(const_iterator pos)
Definition bhopscotch_map.h:325
typename ht::allocator_type allocator_type
Definition bhopscotch_map.h:110
bhopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition bhopscotch_map.h:182
const_iterator cbegin() const noexcept
Definition bhopscotch_map.h:205
T mapped_type
Definition bhopscotch_map.h:103
T & at(const K &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:412
typename ht::pointer pointer
Definition bhopscotch_map.h:113
iterator erase(iterator pos)
Definition bhopscotch_map.h:324
void reserve(size_type count_)
Definition bhopscotch_map.h:667
const_iterator find(const K &key) const
Definition bhopscotch_map.h:530
typename ht::reference reference
Definition bhopscotch_map.h:111
T & operator[](const Key &key)
Definition bhopscotch_map.h:437
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition bhopscotch_map.h:273
bool contains(const K &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:576
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:627
typename ht::size_type size_type
Definition bhopscotch_map.h:105
T & at(const Key &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:377
typename ht::iterator iterator
Definition bhopscotch_map.h:115
bhopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition bhopscotch_map.h:162
const T & at(const Key &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:386
bool contains(const K &key) const
Definition bhopscotch_map.h:564
hasher hash_function() const
Definition bhopscotch_map.h:672
std::pair< iterator, bool > insert(value_type &&value)
Definition bhopscotch_map.h:232
size_type max_bucket_count() const
Definition bhopscotch_map.h:657
float load_factor() const
Definition bhopscotch_map.h:662
size_type erase(const K &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:360
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition bhopscotch_map.h:263
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&...args)
Definition bhopscotch_map.h:303
std::pair< iterator, iterator > equal_range(const Key &key)
Definition bhopscotch_map.h:581
size_type count(const K &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:473
void rehash(size_type count_)
Definition bhopscotch_map.h:666
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:588
void insert(std::initializer_list< value_type > ilist)
Definition bhopscotch_map.h:253
bool empty() const noexcept
Definition bhopscotch_map.h:214
typename ht::hasher hasher
Definition bhopscotch_map.h:107
const_iterator find(const Key &key) const
Definition bhopscotch_map.h:490
std::pair< iterator, bool > insert(const value_type &value)
Definition bhopscotch_map.h:223
bhopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition bhopscotch_map.h:156
iterator find(const Key &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:485
const_iterator end() const noexcept
Definition bhopscotch_map.h:208
typename ht::difference_type difference_type
Definition bhopscotch_map.h:106
size_type bucket_count() const
Definition bhopscotch_map.h:656
bhopscotch_map(std::initializer_list< value_type > init, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition bhopscotch_map.h:168
void max_load_factor(float ml)
Definition bhopscotch_map.h:664
std::pair< iterator, bool > emplace(Args &&...args)
Definition bhopscotch_map.h:285
void insert(InputIt first, InputIt last)
Definition bhopscotch_map.h:251
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:447
iterator find(const K &key, std::size_t precalculated_hash)
Definition bhopscotch_map.h:520
typename ht::key_equal key_equal
Definition bhopscotch_map.h:108
const_iterator cend() const noexcept
Definition bhopscotch_map.h:209
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition bhopscotch_map.h:494
size_type erase(const K &key)
Definition bhopscotch_map.h:347
bhopscotch_map(const Allocator &alloc)
Definition bhopscotch_map.h:140
iterator mutable_iterator(const_iterator pos)
Definition bhopscotch_map.h:683
size_type count(const K &key) const
Definition bhopscotch_map.h:460
float max_load_factor() const
Definition bhopscotch_map.h:663
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition bhopscotch_map.h:258
std::pair< iterator, iterator > equal_range(const K &key)
Definition bhopscotch_map.h:614
bhopscotch_map(InputIt first, InputIt last, size_type bucket_count=ht::DEFAULT_INIT_BUCKETS_SIZE, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition bhopscotch_map.h:146
iterator erase(const_iterator first, const_iterator last)
Definition bhopscotch_map.h:326
T & at(const K &key)
Definition bhopscotch_map.h:399
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&...args)
Definition bhopscotch_map.h:308
const T & at(const Key &key) const
Definition bhopscotch_map.h:382
std::map< Key, T, Compare, Allocator > overflow_container_type
Definition bhopscotch_map.h:95
Definition hopscotch_hash.h:431
const_iterator cend() const noexcept
Definition hopscotch_hash.h:772
std::pair< iterator, bool > emplace(Args &&...args)
Definition hopscotch_hash.h:890
void swap(hopscotch_hash &other)
Definition hopscotch_hash.h:994
std::size_t size_type
Definition hopscotch_hash.h:446
Hash hasher
Definition hopscotch_hash.h:448
value_type & reference
Definition hopscotch_hash.h:451
bool contains(const K &key) const
Definition hopscotch_hash.h:1094
const_iterator cbegin() const noexcept
Definition hopscotch_hash.h:755
size_type max_size() const noexcept
Definition hopscotch_hash.h:785
hopscotch_iterator< true > const_iterator
Definition hopscotch_hash.h:456
float max_load_factor() const
Definition hopscotch_hash.h:1162
value_type * pointer
Definition hopscotch_hash.h:453
size_type count(const K &key) const
Definition hopscotch_hash.h:1070
U::key_compare key_comp() const
Definition hopscotch_hash.h:1211
std::pair< iterator, bool > insert(const value_type &value)
Definition hopscotch_hash.h:800
key_equal key_eq() const
Definition hopscotch_hash.h:1187
std::ptrdiff_t difference_type
Definition hopscotch_hash.h:447
static const size_type DEFAULT_INIT_BUCKETS_SIZE
Definition hopscotch_hash.h:1786
float load_factor() const
Definition hopscotch_hash.h:1153
allocator_type get_allocator() const
Definition hopscotch_hash.h:738
bool empty() const noexcept
Definition hopscotch_hash.h:781
KeyEqual key_equal
Definition hopscotch_hash.h:449
iterator erase(iterator pos)
Definition hopscotch_hash.h:935
U::value_type & at(const K &key)
Definition hopscotch_hash.h:1015
iterator begin() noexcept
Definition hopscotch_hash.h:743
const value_type * const_pointer
Definition hopscotch_hash.h:454
std::pair< iterator, iterator > equal_range(const K &key)
Definition hopscotch_hash.h:1101
Allocator allocator_type
Definition hopscotch_hash.h:450
size_type bucket_count() const
Definition hopscotch_hash.h:1128
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition hopscotch_hash.h:856
size_type max_bucket_count() const
Definition hopscotch_hash.h:1143
void clear() noexcept
Definition hopscotch_hash.h:790
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&...args)
Definition hopscotch_hash.h:901
hasher hash_function() const
Definition hopscotch_hash.h:1185
size_type size() const noexcept
Definition hopscotch_hash.h:783
hopscotch_iterator< false > iterator
Definition hopscotch_hash.h:455
iterator emplace_hint(const_iterator hint, Args &&...args)
Definition hopscotch_hash.h:895
typename KeySelect::key_type key_type
Definition hopscotch_hash.h:444
void rehash(size_type count_)
Definition hopscotch_hash.h:1171
const value_type & const_reference
Definition hopscotch_hash.h:452
iterator end() noexcept
Definition hopscotch_hash.h:765
iterator mutable_iterator(const_iterator pos)
Definition hopscotch_hash.h:1192
void reserve(size_type count_)
Definition hopscotch_hash.h:1177
iterator find(const K &key)
Definition hopscotch_hash.h:1077
size_type overflow_size() const noexcept
Definition hopscotch_hash.h:1207
ValueType value_type
Definition hopscotch_hash.h:445
Definition hopscotch_growth_policy.h:350
Definition bhopscotch_map.h:38
Definition hopscotch_hash.h:60