diff --git a/examples/bench.cc b/examples/bench.cc index 5fbdac3..3f068f1 100644 --- a/examples/bench.cc +++ b/examples/bench.cc @@ -337,6 +337,21 @@ Timer _lookup(vector &v, HT &hash, size_t &num_present) return timer; } +// -------------------------------------------------------------------------- +template +Timer _traverse_empty(int64_t capacity, HT& hash) +{ + hash.clear(); + hash.reserve(capacity); + Timer timer(true); + + for (auto& pair : hash) + if (pair.second) + fprintf(stderr, "should not be here"); + + return timer; +} + // -------------------------------------------------------------------------- template Timer _delete(vector &v, HT &hash) @@ -441,6 +456,10 @@ int main(int argc, char ** argv) timer = _lookup(v, hash, num_present); //fprintf(stderr, "found %zu\n", num_present); } + else if (!strcmp(bench_name, "traverse_empty")) + { + timer = _traverse_empty(num_keys, hash); + } else if(!strcmp(bench_name, "delete")) { vector v(num_keys); diff --git a/parallel_hashmap/phmap.h b/parallel_hashmap/phmap.h index d02f846..48fb04d 100644 --- a/parallel_hashmap/phmap.h +++ b/parallel_hashmap/phmap.h @@ -1245,6 +1245,7 @@ class raw_hash_set ~raw_hash_set() { destroy_slots(); } iterator begin() { + if (empty()) return end(); auto it = iterator_at(0); it.skip_empty_or_deleted(); return it;