24#ifndef TSL_HOPSCOTCH_MAP_H
25#define TSL_HOPSCOTCH_MAP_H
30#include <initializer_list>
78 template <
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
79 class Allocator = std::allocator<std::pair<Key, T>>,
unsigned int NeighborhoodSize = 62,
80 bool StoreHash = false,
class GrowthPolicy = tsl::hh::power_of_two_growth_policy<2>>
94 return key_value.first;
107 return key_value.second;
116 KeyEqual, Allocator, NeighborhoodSize, StoreHash,
141 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
161 template <
class InputIt>
164 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
170 template <
class InputIt>
176 template <
class InputIt>
178 const Allocator &alloc)
185 const KeyEqual &equal = KeyEqual(),
const Allocator &alloc = Allocator())
191 const Allocator &alloc)
197 const Allocator &alloc)
239 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
241 std::pair<iterator, bool>
insert(P &&value)
253 template <class P, typename std::enable_if<std::is_constructible<value_type, P &&>::value>::type
257 return m_ht.
insert(hint, std::forward<P>(value));
265 template <
class InputIt>
void insert(InputIt first, InputIt last) {
m_ht.
insert(first, last); }
267 void insert(std::initializer_list<value_type> ilist)
299 template <
class... Args> std::pair<iterator, bool>
emplace(Args &&...args)
316 template <
class... Args>
327 template <
class... Args>
335 return m_ht.
try_emplace(hint, std::move(k), std::forward<Args>(args)...);
350 return m_ht.
erase(key, precalculated_hash);
358 template <
class K,
class KE = KeyEqual,
359 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
370 template <
class K,
class KE = KeyEqual,
371 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
374 return m_ht.
erase(key, precalculated_hash);
389 T &
at(
const Key &key, std::size_t precalculated_hash)
391 return m_ht.
at(key, precalculated_hash);
394 const T &
at(
const Key &key)
const {
return m_ht.
at(key); }
398 const T &
at(
const Key &key, std::size_t precalculated_hash)
const
400 return m_ht.
at(key, precalculated_hash);
408 template <
class K,
class KE = KeyEqual,
409 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
420 template <
class K,
class KE = KeyEqual,
421 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
422 T &
at(
const K &key, std::size_t precalculated_hash)
424 return m_ht.
at(key, precalculated_hash);
429 template <
class K,
class KE = KeyEqual,
430 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
431 const T &
at(
const K &key)
const
438 template <
class K,
class KE = KeyEqual,
439 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
440 const T &
at(
const K &key, std::size_t precalculated_hash)
const
442 return m_ht.
at(key, precalculated_hash);
457 return m_ht.
count(key, precalculated_hash);
465 template <
class K,
class KE = KeyEqual,
466 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
477 template <
class K,
class KE = KeyEqual,
478 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
481 return m_ht.
count(key, precalculated_hash);
493 return m_ht.
find(key, precalculated_hash);
502 return m_ht.
find(key, precalculated_hash);
510 template <
class K,
class KE = KeyEqual,
511 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
522 template <
class K,
class KE = KeyEqual,
523 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
526 return m_ht.
find(key, precalculated_hash);
531 template <
class K,
class KE = KeyEqual,
532 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
543 template <
class K,
class KE = KeyEqual,
544 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
547 return m_ht.
find(key, precalculated_hash);
557 bool contains(
const Key &key, std::size_t precalculated_hash)
const
567 template <
class K,
class KE = KeyEqual,
568 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
579 template <
class K,
class KE = KeyEqual,
580 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
581 bool contains(
const K &key, std::size_t precalculated_hash)
const
593 std::pair<iterator, iterator>
equal_range(
const Key &key, std::size_t precalculated_hash)
598 std::pair<const_iterator, const_iterator>
equal_range(
const Key &key)
const
605 std::pair<const_iterator, const_iterator>
equal_range(
const Key &key,
606 std::size_t precalculated_hash)
const
616 template <
class K,
class KE = KeyEqual,
617 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
628 template <
class K,
class KE = KeyEqual,
629 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
630 std::pair<iterator, iterator>
equal_range(
const K &key, std::size_t precalculated_hash)
637 template <
class K,
class KE = KeyEqual,
638 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
639 std::pair<const_iterator, const_iterator>
equal_range(
const K &key)
const
646 template <
class K,
class KE = KeyEqual,
647 typename std::enable_if<has_is_transparent<KE>::value>::type * =
nullptr>
648 std::pair<const_iterator, const_iterator>
equal_range(
const K &key,
649 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 Allocator = std::allocator<std::pair<Key, T>>,
unsigned int NeighborhoodSize = 62,
720 bool StoreHash = false>
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
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 hopscotch_map.h:88
key_type & operator()(std::pair< Key, T > &key_value)
Definition hopscotch_map.h:97
const key_type & operator()(const std::pair< Key, T > &key_value) const
Definition hopscotch_map.h:92
Key key_type
Definition hopscotch_map.h:90
Definition hopscotch_map.h:101
T value_type
Definition hopscotch_map.h:103
value_type & operator()(std::pair< Key, T > &key_value)
Definition hopscotch_map.h:110
const value_type & operator()(const std::pair< Key, T > &key_value) const
Definition hopscotch_map.h:105
Definition hopscotch_map.h:82
hopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition hopscotch_map.h:171
bool contains(const K &key) const
Definition hopscotch_map.h:569
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&...args)
Definition hopscotch_map.h:317
size_type count(const Key &key) const
Definition hopscotch_map.h:448
T & operator[](Key &&key)
Definition hopscotch_map.h:446
size_type erase(const key_type &key)
Definition hopscotch_map.h:341
const_iterator cend() const noexcept
Definition hopscotch_map.h:223
typename ht::pointer pointer
Definition hopscotch_map.h:130
T mapped_type
Definition hopscotch_map.h:121
iterator insert(const_iterator hint, const value_type &value)
Definition hopscotch_map.h:248
void insert(std::initializer_list< value_type > ilist)
Definition hopscotch_map.h:267
typename ht::reference reference
Definition hopscotch_map.h:128
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:630
void clear() noexcept
Definition hopscotch_map.h:235
iterator find(const K &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:524
ht m_ht
Definition hopscotch_map.h:711
const T & at(const K &key) const
Definition hopscotch_map.h:431
hasher hash_function() const
Definition hopscotch_map.h:673
const T & at(const K &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:440
iterator erase(iterator pos)
Definition hopscotch_map.h:338
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:348
typename ht::size_type size_type
Definition hopscotch_map.h:123
std::pair< iterator, bool > insert(const value_type &value)
Definition hopscotch_map.h:237
iterator end() noexcept
Definition hopscotch_map.h:221
iterator erase(const_iterator pos)
Definition hopscotch_map.h:339
typename ht::key_type key_type
Definition hopscotch_map.h:120
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition hopscotch_map.h:282
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:593
iterator erase(const_iterator first, const_iterator last)
Definition hopscotch_map.h:340
iterator begin() noexcept
Definition hopscotch_map.h:217
const_iterator end() const noexcept
Definition hopscotch_map.h:222
const_iterator cbegin() const noexcept
Definition hopscotch_map.h:219
const_iterator begin() const noexcept
Definition hopscotch_map.h:218
hopscotch_map()
Definition hopscotch_map.h:138
friend bool operator!=(const hopscotch_map &lhs, const hopscotch_map &rhs)
Definition hopscotch_map.h:703
typename ht::hasher hasher
Definition hopscotch_map.h:125
size_type size() const noexcept
Definition hopscotch_map.h:229
const T & at(const Key &key) const
Definition hopscotch_map.h:394
hopscotch_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition hopscotch_map.h:177
void insert(InputIt first, InputIt last)
Definition hopscotch_map.h:265
void swap(hopscotch_map &other)
Definition hopscotch_map.h:377
void reserve(size_type count_)
Definition hopscotch_map.h:668
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:545
T & at(const K &key)
Definition hopscotch_map.h:410
hopscotch_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition hopscotch_map.h:140
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition hopscotch_map.h:287
bool contains(const K &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:581
typename ht::const_reference const_reference
Definition hopscotch_map.h:129
typename ht::iterator iterator
Definition hopscotch_map.h:132
iterator try_emplace(const_iterator hint, key_type &&k, Args &&...args)
Definition hopscotch_map.h:333
T & operator[](const Key &key)
Definition hopscotch_map.h:445
T & at(const K &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:422
bool contains(const Key &key) const
Definition hopscotch_map.h:550
std::pair< iterator, bool > insert(value_type &&value)
Definition hopscotch_map.h:246
key_equal key_eq() const
Definition hopscotch_map.h:674
typename ht::const_pointer const_pointer
Definition hopscotch_map.h:131
typename ht::key_equal key_equal
Definition hopscotch_map.h:126
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition hopscotch_map.h:639
size_type erase(const K &key)
Definition hopscotch_map.h:360
typename ht::difference_type difference_type
Definition hopscotch_map.h:124
iterator find(const Key &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:491
hopscotch_map(size_type bucket_count, const Allocator &alloc)
Definition hopscotch_map.h:146
hopscotch_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 hopscotch_map.h:162
std::pair< iterator, iterator > equal_range(const Key &key)
Definition hopscotch_map.h:586
hopscotch_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 hopscotch_map.h:183
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition hopscotch_map.h:277
iterator emplace_hint(const_iterator hint, Args &&...args)
Definition hopscotch_map.h:311
size_type erase(const K &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:372
const T & at(const Key &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:398
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition hopscotch_map.h:272
friend bool operator==(const hopscotch_map &lhs, const hopscotch_map &rhs)
Definition hopscotch_map.h:687
size_type count(const K &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:479
void rehash(size_type count_)
Definition hopscotch_map.h:667
hopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition hopscotch_map.h:196
const_iterator find(const Key &key) const
Definition hopscotch_map.h:496
typename ht::allocator_type allocator_type
Definition hopscotch_map.h:127
float max_load_factor() const
Definition hopscotch_map.h:664
T & at(const Key &key, std::size_t precalculated_hash)
Definition hopscotch_map.h:389
typename ht::value_type value_type
Definition hopscotch_map.h:122
hopscotch_map & operator=(std::initializer_list< value_type > ilist)
Definition hopscotch_map.h:202
typename ht::const_iterator const_iterator
Definition hopscotch_map.h:133
iterator insert(const_iterator hint, P &&value)
Definition hopscotch_map.h:255
void max_load_factor(float ml)
Definition hopscotch_map.h:665
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&...args)
Definition hopscotch_map.h:322
bool contains(const Key &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:557
std::pair< iterator, iterator > equal_range(const K &key)
Definition hopscotch_map.h:618
iterator try_emplace(const_iterator hint, const key_type &k, Args &&...args)
Definition hopscotch_map.h:328
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition hopscotch_map.h:598
hopscotch_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition hopscotch_map.h:190
iterator insert(const_iterator hint, value_type &&value)
Definition hopscotch_map.h:260
float load_factor() const
Definition hopscotch_map.h:663
std::pair< iterator, bool > emplace(Args &&...args)
Definition hopscotch_map.h:299
hopscotch_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition hopscotch_map.h:151
T & at(const Key &key)
Definition hopscotch_map.h:382
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:455
allocator_type get_allocator() const
Definition hopscotch_map.h:212
size_type max_size() const noexcept
Definition hopscotch_map.h:230
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:648
size_type max_bucket_count() const
Definition hopscotch_map.h:658
bool empty() const noexcept
Definition hopscotch_map.h:228
std::pair< iterator, bool > insert(P &&value)
Definition hopscotch_map.h:241
hopscotch_map(const Allocator &alloc)
Definition hopscotch_map.h:156
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:500
friend void swap(hopscotch_map &lhs, hopscotch_map &rhs)
Definition hopscotch_map.h:708
size_type count(const K &key) const
Definition hopscotch_map.h:467
size_type bucket_count() const
Definition hopscotch_map.h:657
const_iterator find(const K &key) const
Definition hopscotch_map.h:533
iterator find(const K &key)
Definition hopscotch_map.h:512
size_type overflow_size() const noexcept
Definition hopscotch_map.h:685
iterator mutable_iterator(const_iterator pos)
Definition hopscotch_map.h:683
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition hopscotch_map.h:605
iterator find(const Key &key)
Definition hopscotch_map.h:484
std::list< std::pair< Key, T >, Allocator > overflow_container_type
Definition hopscotch_map.h:113
Definition bhopscotch_map.h:38
Definition hopscotch_hash.h:60