34 template<
typename X=K, std::enable_if_t<std::is_same_v<X,std::type_index>,
int> = 0>
38 template<
typename X=K, std::enable_if_t<!std::is_same_v<X,std::type_index>,
int> = 0>
42 constexpr wfree_unordered_map_item(wfree_unordered_map_item
const &)
noexcept =
delete;
43 constexpr wfree_unordered_map_item(wfree_unordered_map_item &&) noexcept = delete;
44 ~wfree_unordered_map_item() noexcept = default;
45 constexpr wfree_unordered_map_item &operator=(wfree_unordered_map_item const &) noexcept = delete;
46 constexpr wfree_unordered_map_item &operator=(wfree_unordered_map_item &&) noexcept = delete;
58 using mapped_type = V;
61 static constexpr size_t CAPACITY = MAX_NR_ITEMS * 2;
73 static size_t make_hash(K
const &key)
noexcept {
78 void insert(K key, V
value)
noexcept {
79 ttlet
hash = make_hash(key);
81 auto index =
hash % CAPACITY;
83 auto &
item = items[index];
87 if (
item.hash.compare_exchange_strong(item_hash, 1, std::memory_order_acquire)) {
91 item.hash.store(
hash, std::memory_order_release);
94 }
else if (item_hash ==
hash && key ==
item.key) {
105 index = (index + 1) % CAPACITY;
114 for (ttlet &
item: items) {
115 if (
item.hash >= 3) {
122 V& operator[](K
const &key)
noexcept {
123 ttlet
hash = make_hash(key);
125 auto index =
hash % CAPACITY;
127 auto &
item = items[index];
130 size_t item_hash = 0;
131 if (
item.hash.compare_exchange_strong(item_hash, 1, std::memory_order_acquire)) {
134 item.hash.store(
hash, std::memory_order_release);
136 if constexpr (std::is_default_constructible_v<V>) {
144 }
else if (item_hash ==
hash && key ==
item.key) {
154 index = (index + 1) % CAPACITY;
159 std::optional<V> get(K
const &key)
const noexcept {
160 ttlet
hash = make_hash(key);
162 auto index =
hash % CAPACITY;
164 auto &
item = items[index];
166 auto item_hash =
item.hash.load(std::memory_order_acquire);
168 if (item_hash ==
hash && key ==
item.key) {
170 return {
item.value };
172 }
else if (item_hash == 0) {
177 index = (index + 1) % CAPACITY;
182 V get(K
const &key, V
const &default_value)
const noexcept {
183 if (ttlet optional_value = get(key)) {
184 return *optional_value;
186 return default_value;
190 std::optional<V> erase(K
const &key)
noexcept {
191 ttlet
hash = make_hash(key);
193 auto index =
hash % CAPACITY;
195 auto &
item = items[index];
196 auto item_hash =
item.hash.load(std::memory_order_acquire);
198 if (item_hash ==
hash && key ==
item.key) {
200 item.hash.store(1, std::memory_order_release);
201 return {
item.value };
203 }
else if (item_hash == 0) {
208 index = (index + 1) % CAPACITY;