Skip to content
8 changes: 4 additions & 4 deletions libcxx/include/__hash_table
Original file line number Diff line number Diff line change
Expand Up @@ -1771,9 +1771,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) {
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
if (__bc != 0) {
if (__bc != 0 && size() != 0) {
size_t __hash = hash_function()(__k);
size_t __chash = std::__constrain_hash(__hash, __bc);
__next_pointer __nd = __bucket_list_[__chash];
if (__nd != nullptr) {
Expand All @@ -1792,9 +1792,9 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const {
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
if (__bc != 0) {
if (__bc != 0 && size() != 0) {
size_t __hash = hash_function()(__k);
size_t __chash = std::__constrain_hash(__hash, __bc);
__next_pointer __nd = __bucket_list_[__chash];
if (__nd != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void associative_container_benchmarks(std::string container) {
auto get_key = [](Value const& v) { return adapt_operations<Container>::key_from_value(v); };

auto bench = [&](std::string operation, auto f) {
benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(32)->Arg(1024)->Arg(8192);
benchmark::RegisterBenchmark(container + "::" + operation, f)->Arg(0)->Arg(32)->Arg(1024)->Arg(8192);
};

static constexpr bool is_multi_key_container =
Expand Down Expand Up @@ -172,7 +172,7 @@ void associative_container_benchmarks(std::string container) {
// Insertion
/////////////////////////
bench("insert(value) (already present)", [=](auto& st) {
const std::size_t size = st.range(0);
const std::size_t size = st.range(0) ? st.range(0) : 1;
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Value to_insert = in[in.size() / 2]; // pick any existing value
std::vector<Container> c(BatchSize, Container(in.begin(), in.end()));
Expand Down Expand Up @@ -325,7 +325,7 @@ void associative_container_benchmarks(std::string container) {
// Erasure
/////////////////////////
bench("erase(key) (existent)", [=](auto& st) {
const std::size_t size = st.range(0);
const std::size_t size = st.range(0) ? st.range(0) : 1; // avoid empty container
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Value element = in[in.size() / 2]; // pick any element
std::vector<Container> c(BatchSize, Container(in.begin(), in.end()));
Expand Down Expand Up @@ -369,7 +369,7 @@ void associative_container_benchmarks(std::string container) {
});

bench("erase(iterator)", [=](auto& st) {
const std::size_t size = st.range(0);
const std::size_t size = st.range(0) ? st.range(0) : 1; // avoid empty container
std::vector<Value> in = make_value_types(generate_unique_keys(size));
Value element = in[in.size() / 2]; // pick any element

Expand Down Expand Up @@ -448,7 +448,7 @@ void associative_container_benchmarks(std::string container) {
Container c(in.begin(), in.end());

while (st.KeepRunningBatch(BatchSize)) {
for (std::size_t i = 0; i != BatchSize; ++i) {
for (std::size_t i = 0; i != keys.size(); ++i) { // possible empty keys when Arg(0)
auto result = func(c, keys[i]);
benchmark::DoNotOptimize(c);
benchmark::DoNotOptimize(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// UNSUPPORTED: c++03, c++11, c++14, c++17

#include <string>
#include <unordered_set>
#include <utility>

Expand All @@ -27,6 +28,7 @@ struct support::adapt_operations<std::unordered_set<K>> {

int main(int argc, char** argv) {
support::associative_container_benchmarks<std::unordered_set<int>>("std::unordered_set<int>");
support::associative_container_benchmarks<std::unordered_set<std::string>>("std::unordered_set<std::string>");

benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
Expand Down
Loading