24 #ifndef TSL_ROBIN_MAP_H
25 #define TSL_ROBIN_MAP_H
29 #include <initializer_list>
31 #include <type_traits>
86 template <
class Key,
class T,
class Hash = std::hash<Key>,
87 class KeyEqual = std::equal_to<Key>,
88 class Allocator = std::allocator<std::pair<Key, T>>,
89 bool StoreHash = false,
90 class GrowthPolicy = tsl::rh::power_of_two_growth_policy<2>>
101 const std::pair<Key, T>& key_value)
const noexcept {
102 return key_value.first;
106 return key_value.first;
115 const std::pair<Key, T>& key_value)
const noexcept {
116 return key_value.second;
120 return key_value.second;
125 ValueSelect, Hash, KeyEqual,
126 Allocator, StoreHash, GrowthPolicy>;
151 const KeyEqual& equal = KeyEqual(),
152 const Allocator& alloc = Allocator())
162 :
robin_map(
ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {}
164 template <
class InputIt>
167 const Hash& hash = Hash(),
const KeyEqual& equal = KeyEqual(),
168 const Allocator& alloc = Allocator())
173 template <
class InputIt>
175 const Allocator& alloc)
178 template <
class InputIt>
180 const Hash& hash,
const Allocator& alloc)
185 const Hash& hash = Hash(),
const KeyEqual& equal = KeyEqual(),
186 const Allocator& alloc = Allocator())
190 const Allocator& alloc)
195 const Hash& hash,
const Allocator& alloc)
237 template <
class P,
typename std::enable_if<std::is_constructible<
251 template <
class P,
typename std::enable_if<std::is_constructible<
261 template <
class InputIt>
262 void insert(InputIt first, InputIt last) {
266 void insert(std::initializer_list<value_type> ilist) {
297 template <
class... Args>
298 std::pair<iterator, bool>
emplace(Args&&... args) {
309 template <
class... Args>
314 template <
class... Args>
319 template <
class... Args>
324 template <
class... Args>
329 template <
class... Args>
332 std::forward<Args>(args)...);
356 return m_ht.
erase(key, precalculated_hash);
365 class K,
class KE = KeyEqual,
366 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
379 class K,
class KE = KeyEqual,
380 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
382 return m_ht.
erase(key, precalculated_hash);
397 T&
at(
const Key& key, std::size_t precalculated_hash) {
398 return m_ht.
at(key, precalculated_hash);
406 const T&
at(
const Key& key, std::size_t precalculated_hash)
const {
407 return m_ht.
at(key, precalculated_hash);
416 class K,
class KE = KeyEqual,
417 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
418 T&
at(
const K& key) {
430 class K,
class KE = KeyEqual,
431 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
432 T&
at(
const K& key, std::size_t precalculated_hash) {
433 return m_ht.
at(key, precalculated_hash);
440 class K,
class KE = KeyEqual,
441 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
442 const T&
at(
const K& key)
const {
450 class K,
class KE = KeyEqual,
451 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
452 const T&
at(
const K& key, std::size_t precalculated_hash)
const {
453 return m_ht.
at(key, precalculated_hash);
467 return m_ht.
count(key, precalculated_hash);
476 class K,
class KE = KeyEqual,
477 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
490 class K,
class KE = KeyEqual,
491 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
493 return m_ht.
count(key, precalculated_hash);
504 return m_ht.
find(key, precalculated_hash);
513 return m_ht.
find(key, precalculated_hash);
522 class K,
class KE = KeyEqual,
523 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
536 class K,
class KE = KeyEqual,
537 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
539 return m_ht.
find(key, precalculated_hash);
546 class K,
class KE = KeyEqual,
547 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
560 class K,
class KE = KeyEqual,
561 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
563 return m_ht.
find(key, precalculated_hash);
573 bool contains(
const Key& key, std::size_t precalculated_hash)
const {
583 class K,
class KE = KeyEqual,
584 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
597 class K,
class KE = KeyEqual,
598 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
599 bool contains(
const K& key, std::size_t precalculated_hash)
const {
613 std::size_t precalculated_hash) {
625 const Key& key, std::size_t precalculated_hash)
const {
635 class K,
class KE = KeyEqual,
636 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
649 class K,
class KE = KeyEqual,
650 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
652 std::size_t precalculated_hash) {
660 class K,
class KE = KeyEqual,
661 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
662 std::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const {
670 class K,
class KE = KeyEqual,
671 typename std::enable_if<has_is_transparent<KE>::value>::type* =
nullptr>
673 const K& key, std::size_t precalculated_hash)
const {
736 template <
class Serializer>
767 template <
class Deserializer>
769 bool hash_compatible =
false) {
781 for (
const auto& element_lhs : lhs) {
782 const auto it_element_rhs = rhs.
find(element_lhs.first);
783 if (it_element_rhs == rhs.
cend() ||
784 element_lhs.second != it_element_rhs->second) {
806 template <
class Key,
class T,
class Hash = std::hash<Key>,
807 class KeyEqual = std::equal_to<Key>,
808 class Allocator = std::allocator<std::pair<Key, T>>,
809 bool StoreHash = false>