36 value(), hash(0), key(
std::type_index(typeid(
void)))
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 std::size_t CAPACITY = MAX_NR_ITEMS * 2;
76 return hash >= 3 ? hash : hash + 3;
79 void insert(K key, V value)
noexcept
81 hilet hash = make_hash(key);
83 auto index = hash % CAPACITY;
85 auto &item = items[index];
89 if (item.hash.compare_exchange_strong(item_hash, 1, std::memory_order::acquire)) {
93 item.hash.store(hash, std::memory_order::release);
96 }
else if (item_hash == hash && key == item.key) {
107 index = (index + 1) % CAPACITY;
117 for (
hilet &item : items) {
118 if (item.hash >= 3) {
125 V &operator[](K
const &key)
noexcept
127 hilet hash = make_hash(key);
129 auto index = hash % CAPACITY;
131 auto &item = items[index];
135 if (item.hash.compare_exchange_strong(item_hash, 1, std::memory_order::acquire)) {
138 item.hash.store(hash, std::memory_order::release);
140 if constexpr (std::is_default_constructible_v<V>) {
148 }
else if (item_hash == hash && key == item.key) {
158 index = (index + 1) % CAPACITY;
163 std::optional<V> get(K
const &key)
const noexcept
165 hilet hash = make_hash(key);
167 auto index = hash % CAPACITY;
169 auto &item = items[index];
171 auto item_hash = item.hash.load(std::memory_order::acquire);
173 if (item_hash == hash && key == item.key) {
177 }
else if (item_hash == 0) {
182 index = (index + 1) % CAPACITY;
187 V get(K
const &key, V
const &default_value)
const noexcept
189 if (
hilet optional_value = get(key)) {
190 return *optional_value;
192 return default_value;
196 std::optional<V> erase(K
const &key)
noexcept
198 hilet hash = make_hash(key);
200 auto index = hash % CAPACITY;
202 auto &item = items[index];
203 auto item_hash = item.hash.load(std::memory_order::acquire);
205 if (item_hash == hash && key == item.key) {
207 item.hash.store(1, std::memory_order::release);
210 }
else if (item_hash == 0) {
215 index = (index + 1) % CAPACITY;