20#ifndef REVERSE_PURGE_HASH_MAP_HPP_
21#define REVERSE_PURGE_HASH_MAP_HPP_
39 typename V = uint64_t,
40 typename H = std::hash<K>,
41 typename E = std::equal_to<K>,
42 typename A = std::allocator<K>
44class reverse_purge_hash_map {
46 using AllocV =
typename std::allocator_traits<A>::template rebind_alloc<V>;
47 using AllocU16 =
typename std::allocator_traits<A>::template rebind_alloc<uint16_t>;
49 reverse_purge_hash_map(uint8_t lg_size, uint8_t lg_max_size,
const E& equal,
const A& allocator);
50 reverse_purge_hash_map(
const reverse_purge_hash_map& other);
51 reverse_purge_hash_map(reverse_purge_hash_map&& other)
noexcept;
52 ~reverse_purge_hash_map();
53 reverse_purge_hash_map& operator=(
const reverse_purge_hash_map& other);
54 reverse_purge_hash_map& operator=(reverse_purge_hash_map&& other);
56 template<
typename FwdK>
57 V adjust_or_insert(FwdK&& key, V value);
59 V get(
const K& key)
const;
60 uint8_t get_lg_cur_size()
const;
61 uint8_t get_lg_max_size()
const;
62 uint32_t get_capacity()
const;
63 uint32_t get_num_active()
const;
64 const A& get_allocator()
const;
67 iterator begin()
const;
71 static constexpr double LOAD_FACTOR = 0.75;
72 static constexpr uint16_t DRIFT_LIMIT = 1024;
73 static constexpr uint32_t MAX_SAMPLE_SIZE = 1024;
84 inline bool is_active(uint32_t probe)
const;
85 void subtract_and_keep_positive_only(V amount);
86 void hash_delete(uint32_t probe);
87 uint32_t internal_adjust_or_insert(
const K& key, V value);
88 V resize_or_purge_if_needed();
89 void resize(uint8_t lg_new_size);
94template<
typename K,
typename V,
typename H,
typename E,
typename A>
95class reverse_purge_hash_map<K, V, H, E, A>::iterator {
97 using iterator_category = std::input_iterator_tag;
98 using value_type = std::pair<K&, V>;
99 using difference_type = void;
100 using pointer = void;
101 using reference =
const value_type;
103 friend class reverse_purge_hash_map<K, V, H, E, A>;
104 iterator& operator++() {
106 if (count < map->num_active_) {
107 const uint32_t mask = (1 << map->lg_cur_size_) - 1;
109 index = (index + stride) & mask;
110 }
while (!map->is_active(index));
114 iterator operator++(
int) { iterator tmp(*
this); operator++();
return tmp; }
115 bool operator==(
const iterator& rhs)
const {
return count == rhs.count; }
116 bool operator!=(
const iterator& rhs)
const {
return count != rhs.count; }
117 reference operator*()
const {
118 return value_type(map->keys_[index], map->values_[index]);
121 static constexpr double GOLDEN_RATIO_RECIPROCAL = 0.6180339887498949;
122 const reverse_purge_hash_map<K, V, H, E, A>* map;
126 iterator(
const reverse_purge_hash_map<K, V, H, E, A>* map, uint32_t index, uint32_t count):
127 map(map), index(index), count(count), stride(static_cast<uint32_t>((1 << map->lg_cur_size_) * GOLDEN_RATIO_RECIPROCAL) | 1) {}
132#include "reverse_purge_hash_map_impl.hpp"
DataSketches namespace.
Definition binomial_bounds.hpp:38