Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
martinus committed Dec 11, 2023
1 parent ea7622e commit f3ce99b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions include/ankerl/unordered_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,10 @@ class table : public std::conditional_t<is_map_v<T>, base_table_type_map<T>, bas

template <typename K, typename... Args>
auto do_try_emplace(K&& key, Args&&... args) -> std::pair<iterator, bool> {
if (ANKERL_UNORDERED_DENSE_UNLIKELY(is_full())) {
if (ANKERL_UNORDERED_DENSE_UNLIKELY(0U == m_max_bucket_capacity)) {
// only happens when map is initially empty
increase_size();
}

auto hash = mixed_hash(key);
auto dist_and_fingerprint = dist_and_fingerprint_from_hash(hash);
auto bucket_idx = bucket_idx_from_hash(hash);
Expand All @@ -1050,6 +1050,15 @@ class table : public std::conditional_t<is_map_v<T>, base_table_type_map<T>, bas
return {begin() + static_cast<difference_type>(bucket->m_value_idx), false};
}
} else if (dist_and_fingerprint > bucket->m_dist_and_fingerprint) {
if (ANKERL_UNORDERED_DENSE_UNLIKELY(is_full())) {
// emplace the new value, and then increase size to rehash!
m_values.emplace_back(std::piecewise_construct,
std::forward_as_tuple(std::forward<K>(key)),
std::forward_as_tuple(std::forward<Args>(args)...));
increase_size();
auto value_idx = static_cast<value_idx_type>(m_values.size() - 1);
return {begin() + static_cast<difference_type>(value_idx), true};
}
return do_place_element(dist_and_fingerprint, bucket_idx, std::forward<K>(key), std::forward<Args>(args)...);
}
dist_and_fingerprint = dist_inc(dist_and_fingerprint);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TYPE_TO_STRING_MAP(counter::obj,
std::equal_to<counter::obj>,
std::allocator<std::pair<counter::obj, counter::obj>>,
bucket_micro);

#if 0
TEST_CASE_MAP("bucket_micro",
counter::obj,
counter::obj,
Expand Down Expand Up @@ -76,3 +76,4 @@ TEST_CASE_MAP("bucket_micro",
REQUIRE(it->second.get() == i);
}
}
#endif

0 comments on commit f3ce99b

Please sign in to comment.