39 value(), hash(0), key(
std::type_index(typeid(
void)))
45 constexpr wfree_unordered_map_item(wfree_unordered_map_item
const &)
noexcept =
delete;
46 constexpr wfree_unordered_map_item(wfree_unordered_map_item &&) noexcept = delete;
47 ~wfree_unordered_map_item() noexcept = default;
48 constexpr wfree_unordered_map_item &operator=(wfree_unordered_map_item const &) noexcept = delete;
49 constexpr wfree_unordered_map_item &operator=(wfree_unordered_map_item &&) noexcept = delete;
61 using mapped_type = V;
64 constexpr static std::size_t CAPACITY = MAX_NR_ITEMS * 2;
79 return hash >= 3 ? hash : hash + 3;
82 void insert(K key, V value)
noexcept
84 hilet hash = make_hash(key);
86 auto index = hash % CAPACITY;
88 auto &item = items[index];
92 if (item.hash.compare_exchange_strong(item_hash, 1, std::memory_order::acquire)) {
96 item.hash.store(hash, std::memory_order::release);
99 }
else if (item_hash == hash && key == item.key) {
110 index = (index + 1) % CAPACITY;
120 for (hilet &item : items) {
121 if (item.hash >= 3) {
128 V &operator[](K
const &key)
noexcept
130 hilet hash = make_hash(key);
132 auto index = hash % CAPACITY;
134 auto &item = items[index];
138 if (item.hash.compare_exchange_strong(item_hash, 1, std::memory_order::acquire)) {
141 item.hash.store(hash, std::memory_order::release);
143 if constexpr (std::is_default_constructible_v<V>) {
151 }
else if (item_hash == hash && key == item.key) {
161 index = (index + 1) % CAPACITY;
166 std::optional<V> get(K
const &key)
const noexcept
168 hilet hash = make_hash(key);
170 auto index = hash % CAPACITY;
172 auto &item = items[index];
174 auto item_hash = item.hash.load(std::memory_order::acquire);
176 if (item_hash == hash && key == item.key) {
180 }
else if (item_hash == 0) {
185 index = (index + 1) % CAPACITY;
190 V get(K
const &key, V
const &default_value)
const noexcept
192 if (hilet optional_value = get(key)) {
193 return *optional_value;
195 return default_value;
199 std::optional<V> erase(K
const &key)
noexcept
201 hilet hash = make_hash(key);
203 auto index = hash % CAPACITY;
205 auto &item = items[index];
206 auto item_hash = item.hash.load(std::memory_order::acquire);
208 if (item_hash == hash && key == item.key) {
210 item.hash.store(1, std::memory_order::release);
213 }
else if (item_hash == 0) {
218 index = (index + 1) % CAPACITY;