24 #ifndef TSL_ROBIN_MAP_H 25 #define TSL_ROBIN_MAP_H 30 #include <initializer_list> 32 #include <type_traits> 80 class Hash = std::hash<Key>,
81 class KeyEqual = std::equal_to<Key>,
82 class Allocator = std::allocator<std::pair<Key, T>>,
83 bool StoreHash =
false,
94 const key_type& operator()(
const std::pair<Key, T>& key_value)
const noexcept {
95 return key_value.first;
98 key_type& operator()(std::pair<Key, T>& key_value)
noexcept {
99 return key_value.first;
105 using value_type = T;
107 const value_type& operator()(
const std::pair<Key, T>& key_value)
const noexcept {
108 return key_value.second;
111 value_type& operator()(std::pair<Key, T>& key_value)
noexcept {
112 return key_value.second;
117 Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
120 using key_type =
typename ht::key_type;
121 using mapped_type = T;
122 using value_type =
typename ht::value_type;
123 using size_type =
typename ht::size_type;
124 using difference_type =
typename ht::difference_type;
125 using hasher =
typename ht::hasher;
126 using key_equal =
typename ht::key_equal;
127 using allocator_type =
typename ht::allocator_type;
128 using reference =
typename ht::reference;
129 using const_reference =
typename ht::const_reference;
130 using pointer =
typename ht::pointer;
131 using const_pointer =
typename ht::const_pointer;
132 using iterator =
typename ht::iterator;
133 using const_iterator =
typename ht::const_iterator;
144 const Hash& hash = Hash(),
145 const KeyEqual& equal = KeyEqual(),
146 const Allocator& alloc = Allocator()):
147 m_ht(bucket_count, hash, equal, alloc)
152 const Allocator& alloc):
robin_map(bucket_count, Hash(), KeyEqual(), alloc)
158 const Allocator& alloc):
robin_map(bucket_count, hash, KeyEqual(), alloc)
165 template<
class InputIt>
167 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
168 const Hash& hash = Hash(),
169 const KeyEqual& equal = KeyEqual(),
170 const Allocator& alloc = Allocator()):
robin_map(bucket_count, hash, equal, alloc)
175 template<
class InputIt>
177 size_type bucket_count,
178 const Allocator& alloc):
robin_map(first, last, bucket_count, Hash(), KeyEqual(), alloc)
182 template<
class InputIt>
184 size_type bucket_count,
186 const Allocator& alloc):
robin_map(first, last, bucket_count, hash, KeyEqual(), alloc)
191 size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
192 const Hash& hash = Hash(),
193 const KeyEqual& equal = KeyEqual(),
194 const Allocator& alloc = Allocator()):
195 robin_map(init.begin(), init.end(), bucket_count, hash, equal, alloc)
200 size_type bucket_count,
201 const Allocator& alloc):
202 robin_map(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(), alloc)
207 size_type bucket_count,
209 const Allocator& alloc):
210 robin_map(init.begin(), init.end(), bucket_count, hash, KeyEqual(), alloc)
217 m_ht.reserve(ilist.size());
218 m_ht.insert(ilist.begin(), ilist.end());
229 iterator
begin()
noexcept {
return m_ht.begin(); }
230 const_iterator
begin()
const noexcept {
return m_ht.begin(); }
231 const_iterator
cbegin()
const noexcept {
return m_ht.cbegin(); }
233 iterator
end()
noexcept {
return m_ht.end(); }
234 const_iterator
end()
const noexcept {
return m_ht.end(); }
235 const_iterator
cend()
const noexcept {
return m_ht.cend(); }
241 bool empty()
const noexcept {
return m_ht.empty(); }
242 size_type
size()
const noexcept {
return m_ht.size(); }
243 size_type
max_size()
const noexcept {
return m_ht.max_size(); }
248 void clear()
noexcept { m_ht.clear(); }
252 std::pair<iterator,
bool>
insert(
const value_type& value) {
253 return m_ht.insert(value);
256 template<
class P,
typename std::enable_if<std::is_constructible<value_type, P&&>::value>::type* =
nullptr>
257 std::pair<iterator,
bool>
insert(P&& value) {
258 return m_ht.emplace(std::forward<P>(value));
261 std::pair<iterator,
bool>
insert(value_type&& value) {
262 return m_ht.insert(std::move(value));
266 iterator
insert(const_iterator hint,
const value_type& value) {
267 return m_ht.insert_hint(hint, value);
270 template<
class P,
typename std::enable_if<std::is_constructible<value_type, P&&>::value>::type* =
nullptr>
271 iterator
insert(const_iterator hint, P&& value) {
272 return m_ht.emplace_hint(hint, std::forward<P>(value));
275 iterator
insert(const_iterator hint, value_type&& value) {
276 return m_ht.insert_hint(hint, std::move(value));
280 template<
class InputIt>
281 void insert(InputIt first, InputIt last) {
282 m_ht.insert(first, last);
285 void insert(std::initializer_list<value_type> ilist) {
286 m_ht.insert(ilist.begin(), ilist.end());
294 return m_ht.insert_or_assign(k, std::forward<M>(obj));
299 return m_ht.insert_or_assign(std::move(k), std::forward<M>(obj));
304 return m_ht.insert_or_assign(hint, k, std::forward<M>(obj));
309 return m_ht.insert_or_assign(hint, std::move(k), std::forward<M>(obj));
320 template<
class... Args>
321 std::pair<iterator,
bool>
emplace(Args&&... args) {
322 return m_ht.emplace(std::forward<Args>(args)...);
333 template<
class... Args>
335 return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
341 template<
class... Args>
342 std::pair<iterator,
bool>
try_emplace(
const key_type& k, Args&&... args) {
343 return m_ht.try_emplace(k, std::forward<Args>(args)...);
346 template<
class... Args>
347 std::pair<iterator,
bool>
try_emplace(key_type&& k, Args&&... args) {
348 return m_ht.try_emplace(std::move(k), std::forward<Args>(args)...);
351 template<
class... Args>
352 iterator
try_emplace(const_iterator hint,
const key_type& k, Args&&... args) {
353 return m_ht.try_emplace_hint(hint, k, std::forward<Args>(args)...);
356 template<
class... Args>
357 iterator
try_emplace(const_iterator hint, key_type&& k, Args&&... args) {
358 return m_ht.try_emplace_hint(hint, std::move(k), std::forward<Args>(args)...);
364 iterator
erase(iterator pos) {
return m_ht.erase(pos); }
365 iterator
erase(const_iterator pos) {
return m_ht.erase(pos); }
366 iterator
erase(const_iterator first, const_iterator last) {
return m_ht.erase(first, last); }
367 size_type
erase(
const key_type& key) {
return m_ht.erase(key); }
373 size_type
erase(
const key_type& key, std::size_t precalculated_hash) {
374 return m_ht.erase(key, precalculated_hash);
381 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
382 size_type
erase(
const K& key) {
return m_ht.erase(key); }
390 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
391 size_type
erase(
const K& key, std::size_t precalculated_hash) {
392 return m_ht.erase(key, precalculated_hash);
404 T&
at(
const Key& key) {
return m_ht.at(key); }
410 T&
at(
const Key& key, std::size_t precalculated_hash) {
return m_ht.at(key, precalculated_hash); }
413 const T&
at(
const Key& key)
const {
return m_ht.at(key); }
418 const T&
at(
const Key& key, std::size_t precalculated_hash)
const {
return m_ht.at(key, precalculated_hash); }
425 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
426 T&
at(
const K& key) {
return m_ht.at(key); }
434 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
435 T&
at(
const K& key, std::size_t precalculated_hash) {
return m_ht.at(key, precalculated_hash); }
441 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
442 const T&
at(
const K& key)
const {
return m_ht.at(key); }
447 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
448 const T&
at(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.at(key, precalculated_hash); }
453 T&
operator[](
const Key& key) {
return m_ht[key]; }
454 T&
operator[](Key&& key) {
return m_ht[std::move(key)]; }
459 size_type
count(
const Key& key)
const {
return m_ht.count(key); }
465 size_type
count(
const Key& key, std::size_t precalculated_hash)
const {
466 return m_ht.count(key, precalculated_hash);
473 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
474 size_type
count(
const K& key)
const {
return m_ht.count(key); }
482 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
483 size_type
count(
const K& key, std::size_t precalculated_hash)
const {
return m_ht.count(key, precalculated_hash); }
488 iterator
find(
const Key& key) {
return m_ht.find(key); }
494 iterator
find(
const Key& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
496 const_iterator
find(
const Key& key)
const {
return m_ht.find(key); }
501 const_iterator
find(
const Key& key, std::size_t precalculated_hash)
const {
502 return m_ht.find(key, precalculated_hash);
509 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
510 iterator
find(
const K& key) {
return m_ht.find(key); }
518 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
519 iterator
find(
const K& key, std::size_t precalculated_hash) {
return m_ht.find(key, precalculated_hash); }
524 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
525 const_iterator
find(
const K& key)
const {
return m_ht.find(key); }
533 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
534 const_iterator
find(
const K& key, std::size_t precalculated_hash)
const {
535 return m_ht.find(key, precalculated_hash);
541 std::pair<iterator, iterator>
equal_range(
const Key& key) {
return m_ht.equal_range(key); }
547 std::pair<iterator, iterator>
equal_range(
const Key& key, std::size_t precalculated_hash) {
548 return m_ht.equal_range(key, precalculated_hash);
551 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
return m_ht.equal_range(key); }
556 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key, std::size_t precalculated_hash)
const {
557 return m_ht.equal_range(key, precalculated_hash);
564 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
565 std::pair<iterator, iterator>
equal_range(
const K& key) {
return m_ht.equal_range(key); }
574 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
575 std::pair<iterator, iterator>
equal_range(
const K& key, std::size_t precalculated_hash) {
576 return m_ht.equal_range(key, precalculated_hash);
582 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
583 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
return m_ht.equal_range(key); }
588 template<
class K,
class KE = KeyEqual,
typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
589 std::pair<const_iterator, const_iterator>
equal_range(
const K& key, std::size_t precalculated_hash)
const {
590 return m_ht.equal_range(key, precalculated_hash);
622 void rehash(size_type count) { m_ht.rehash(count); }
623 void reserve(size_type count) { m_ht.reserve(count); }
630 key_equal
key_eq()
const {
return m_ht.key_eq(); }
640 return m_ht.mutable_iterator(pos);
644 if(lhs.size() != rhs.size()) {
648 for(
const auto& element_lhs: lhs) {
649 const auto it_element_rhs = rhs.find(element_lhs.first);
650 if(it_element_rhs == rhs.cend() || element_lhs.second != it_element_rhs->second) {
659 return !operator==(lhs, rhs);
676 class Hash = std::hash<Key>,
677 class KeyEqual = std::equal_to<Key>,
678 class Allocator = std::allocator<std::pair<Key, T>>,
679 bool StoreHash =
false>
robin_map(size_type bucket_count, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual(), const Allocator &alloc=Allocator())
Definition: robin_map.h:143
size_type max_bucket_count() const
Definition: robin_map.h:600
iterator end() noexcept
Definition: robin_map.h:233
Definition: robin_growth_policy.h:69
float min_load_factor() const
Definition: robin_map.h:608
hasher hash_function() const
Definition: robin_map.h:629
iterator find(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:519
const T & at(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:448
std::pair< iterator, bool > insert(P &&value)
Definition: robin_map.h:257
T & operator[](const Key &key)
Definition: robin_map.h:453
iterator find(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:494
T & at(const K &key)
Definition: robin_map.h:426
const T & at(const K &key) const
Definition: robin_map.h:442
size_type erase(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:391
friend bool operator!=(const robin_map &lhs, const robin_map &rhs)
Definition: robin_map.h:658
Definition: robin_growth_policy.h:68
iterator erase(const_iterator first, const_iterator last)
Definition: robin_map.h:366
const_iterator find(const Key &key) const
Definition: robin_map.h:496
std::pair< iterator, bool > insert(const value_type &value)
Definition: robin_map.h:252
void insert(InputIt first, InputIt last)
Definition: robin_map.h:281
const_iterator find(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:534
iterator begin() noexcept
Definition: robin_map.h:229
const_iterator begin() const noexcept
Definition: robin_map.h:230
std::pair< iterator, iterator > equal_range(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:547
void max_load_factor(float ml)
Definition: robin_map.h:620
void swap(robin_map &other)
Definition: robin_map.h:397
const_iterator end() const noexcept
Definition: robin_map.h:234
iterator insert(const_iterator hint, value_type &&value)
Definition: robin_map.h:275
size_type count(const K &key) const
Definition: robin_map.h:474
bool empty() const noexcept
Definition: robin_map.h:241
size_type bucket_count() const
Definition: robin_map.h:599
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: robin_map.h:541
T & operator[](Key &&key)
Definition: robin_map.h:454
Definition: robin_map.h:85
size_type max_size() const noexcept
Definition: robin_map.h:243
const T & at(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:418
iterator try_emplace(const_iterator hint, const key_type &k, Args &&... args)
Definition: robin_map.h:352
std::pair< iterator, bool > insert_or_assign(const key_type &k, M &&obj)
Definition: robin_map.h:293
size_type count(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:483
robin_map & operator=(std::initializer_list< value_type > ilist)
Definition: robin_map.h:214
std::pair< iterator, bool > try_emplace(const key_type &k, Args &&... args)
Definition: robin_map.h:342
iterator insert_or_assign(const_iterator hint, const key_type &k, M &&obj)
Definition: robin_map.h:303
key_equal key_eq() const
Definition: robin_map.h:630
void min_load_factor(float ml)
Definition: robin_map.h:619
void rehash(size_type count)
Definition: robin_map.h:622
robin_map(size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:151
robin_map()
Definition: robin_map.h:140
std::pair< iterator, bool > try_emplace(key_type &&k, Args &&... args)
Definition: robin_map.h:347
T & at(const Key &key, std::size_t precalculated_hash)
Definition: robin_map.h:410
size_type erase(const K &key)
Definition: robin_map.h:382
iterator insert(const_iterator hint, P &&value)
Definition: robin_map.h:271
std::pair< iterator, iterator > equal_range(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:575
float load_factor() const
Definition: robin_map.h:606
iterator erase(const_iterator pos)
Definition: robin_map.h:365
std::pair< const_iterator, const_iterator > equal_range(const K &key) const
Definition: robin_map.h:583
const_iterator find(const K &key) const
Definition: robin_map.h:525
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:199
const T & at(const Key &key) const
Definition: robin_map.h:413
const_iterator find(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:501
robin_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: robin_map.h:166
std::pair< const_iterator, const_iterator > equal_range(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:556
T & at(const Key &key)
Definition: robin_map.h:404
allocator_type get_allocator() const
Definition: robin_map.h:223
iterator find(const Key &key)
Definition: robin_map.h:488
robin_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: robin_map.h:190
robin_map(InputIt first, InputIt last, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:183
std::pair< iterator, bool > insert_or_assign(key_type &&k, M &&obj)
Definition: robin_map.h:298
iterator find(const K &key)
Definition: robin_map.h:510
void reserve(size_type count)
Definition: robin_map.h:623
const_iterator cbegin() const noexcept
Definition: robin_map.h:231
friend bool operator==(const robin_map &lhs, const robin_map &rhs)
Definition: robin_map.h:643
size_type count(const Key &key) const
Definition: robin_map.h:459
T & at(const K &key, std::size_t precalculated_hash)
Definition: robin_map.h:435
iterator emplace_hint(const_iterator hint, Args &&... args)
Definition: robin_map.h:334
size_type count(const Key &key, std::size_t precalculated_hash) const
Definition: robin_map.h:465
Definition: robin_growth_policy.h:276
robin_map(std::initializer_list< value_type > init, size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:206
std::pair< iterator, iterator > equal_range(const K &key)
Definition: robin_map.h:565
void insert(std::initializer_list< value_type > ilist)
Definition: robin_map.h:285
robin_map(const Allocator &alloc)
Definition: robin_map.h:162
void clear() noexcept
Definition: robin_map.h:248
Definition: robin_hash.h:317
robin_map(InputIt first, InputIt last, size_type bucket_count, const Allocator &alloc)
Definition: robin_map.h:176
iterator insert(const_iterator hint, const value_type &value)
Definition: robin_map.h:266
friend void swap(robin_map &lhs, robin_map &rhs)
Definition: robin_map.h:662
size_type size() const noexcept
Definition: robin_map.h:242
size_type erase(const key_type &key)
Definition: robin_map.h:367
std::pair< const_iterator, const_iterator > equal_range(const K &key, std::size_t precalculated_hash) const
Definition: robin_map.h:589
std::pair< iterator, bool > insert(value_type &&value)
Definition: robin_map.h:261
iterator erase(iterator pos)
Definition: robin_map.h:364
iterator insert_or_assign(const_iterator hint, key_type &&k, M &&obj)
Definition: robin_map.h:308
robin_map(size_type bucket_count, const Hash &hash, const Allocator &alloc)
Definition: robin_map.h:156
Definition: robin_growth_policy.h:78
float max_load_factor() const
Definition: robin_map.h:609
const_iterator cend() const noexcept
Definition: robin_map.h:235
iterator mutable_iterator(const_iterator pos)
Definition: robin_map.h:639
size_type erase(const key_type &key, std::size_t precalculated_hash)
Definition: robin_map.h:373
Definition: robin_hash.h:47
iterator try_emplace(const_iterator hint, key_type &&k, Args &&... args)
Definition: robin_map.h:357
std::pair< iterator, bool > emplace(Args &&... args)
Definition: robin_map.h:321
std::pair< const_iterator, const_iterator > equal_range(const Key &key) const
Definition: robin_map.h:551