| 140 | } |
| 141 | |
| 142 | Index::LookupResult SparseMapIndex::insert(uint64_t key, |
| 143 | uint32_t address, |
| 144 | uint16_t sizeHint) { |
| 145 | auto& map = getMap(key); |
| 146 | auto lock = std::lock_guard{getMutex(key)}; |
| 147 | auto it = map.find(subkey(key)); |
| 148 | if (it != map.end()) { |
| 149 | LookupResult lr{true, it->second}; |
| 150 | |
| 151 | trackRemove(it->second); |
| 152 | // tsl::sparse_map's `it->second` is immutable, while it.value() is |
| 153 | // mutable |
| 154 | it.value().address = address; |
| 155 | it.value().currentHits = 0; |
| 156 | it.value().extra = {0}; |
| 157 | it.value().sizeHint = sizeHint; |
| 158 | return lr; |
| 159 | } |
| 160 | map.try_emplace(subkey(key), address, sizeHint); |
| 161 | |
| 162 | return {}; |
| 163 | } |
| 164 | |
| 165 | Index::LookupResult SparseMapIndex::insertIfNotExists(uint64_t key, |
| 166 | uint32_t address, |