| 344 | /*! \return True if the element has been inserted */ |
| 345 | template<class K, class T, std::uint32_t Capacity, class HashFunc> |
| 346 | bool StaticHashMap<K, T, Capacity, HashFunc>::insert(const K& key, const T& value) |
| 347 | { |
| 348 | const hash_t hash = hashFunc_(key); |
| 349 | std::uint32_t bucketIndex = hash % Capacity; |
| 350 | |
| 351 | if (bucketFoundOrEmpty(bucketIndex, hash, key) == false) { |
| 352 | if (delta1_[bucketIndex] != 0) { |
| 353 | bucketIndex = addDelta1(bucketIndex); |
| 354 | if (bucketFound(bucketIndex, hash, key) == false) { |
| 355 | while (delta2_[bucketIndex] != 0) { |
| 356 | bucketIndex = addDelta2(bucketIndex); |
| 357 | // Found at ideal index + delta1 + (n * delta2) |
| 358 | if (bucketFound(bucketIndex, hash, key)) { |
| 359 | return false; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | // Adding at ideal index + delta1 + (n * delta2) |
| 364 | const std::uint32_t newIndex = linearSearch(bucketIndex + 1, hash, key); |
| 365 | delta2_[bucketIndex] = calcNewDelta(bucketIndex, newIndex); |
| 366 | insertNode(newIndex, hash, key, value); |
| 367 | return true; |
| 368 | } else { |
| 369 | // Found at ideal index + delta1 |
| 370 | return false; |
| 371 | } |
| 372 | } else { |
| 373 | // Adding at ideal index + delta1 |
| 374 | const std::uint32_t newIndex = linearSearch(bucketIndex + 1, hash, key); |
| 375 | delta1_[bucketIndex] = calcNewDelta(bucketIndex, newIndex); |
| 376 | insertNode(newIndex, hash, key, value); |
| 377 | return true; |
| 378 | } |
| 379 | } else { |
| 380 | // Using the ideal bucket index for the node |
| 381 | if (hashes_[bucketIndex] == NullHash) { |
| 382 | insertNode(bucketIndex, hash, key, value); |
| 383 | return true; |
| 384 | } else { |
| 385 | return false; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /*! \return True if the element has been inserted */ |
| 391 | template<class K, class T, std::uint32_t Capacity, class HashFunc> |
no outgoing calls
no test coverage detected