MCPcopy Create free account
hub / github.com/Tessil/ordered-map / insert_impl

Method insert_impl

include/tsl/ordered_hash.h:1372–1408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1370 */
1371 template <class K, class... Args>
1372 std::pair<iterator, bool> insert_impl(const K& key,
1373 Args&&... value_type_args) {
1374 const std::size_t hash = hash_key(key);
1375
1376 std::size_t ibucket = bucket_for_hash(hash);
1377 std::size_t dist_from_ideal_bucket = 0;
1378
1379 while (!m_buckets[ibucket].empty() &&
1380 dist_from_ideal_bucket <= distance_from_ideal_bucket(ibucket)) {
1381 if (m_buckets[ibucket].truncated_hash() ==
1382 bucket_entry::truncate_hash(hash) &&
1383 compare_keys(key,
1384 KeySelect()(m_values[m_buckets[ibucket].index()]))) {
1385 return std::make_pair(begin() + m_buckets[ibucket].index(), false);
1386 }
1387
1388 ibucket = next_bucket(ibucket);
1389 dist_from_ideal_bucket++;
1390 }
1391
1392 if (size() >= max_size()) {
1393 TSL_OH_THROW_OR_TERMINATE(
1394 std::length_error, "We reached the maximum size for the hash table.");
1395 }
1396
1397 if (grow_on_high_load()) {
1398 ibucket = bucket_for_hash(hash);
1399 dist_from_ideal_bucket = 0;
1400 }
1401
1402 m_values.emplace_back(std::forward<Args>(value_type_args)...);
1403 insert_index(ibucket, dist_from_ideal_bucket,
1404 index_type(m_values.size() - 1),
1405 bucket_entry::truncate_hash(hash));
1406
1407 return std::make_pair(std::prev(end()), true);
1408 }
1409
1410 /**
1411 * Insert the element before insert_position.

Callers

nothing calls this directly

Calls 5

truncated_hashMethod · 0.80
indexMethod · 0.80
KeySelectClass · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected