mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
Make begin() to return end() on empty tables. (#297)
Eliminate performance overhead in constructing begin() iterators on empty hash tables.
This commit is contained in:
@@ -337,6 +337,21 @@ Timer _lookup(vector<T> &v, HT &hash, size_t &num_present)
|
||||
return timer;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
template <class HT>
|
||||
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 <class T, class HT>
|
||||
Timer _delete(vector<T> &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<int64_t> v(num_keys);
|
||||
|
||||
Vendored
+1
@@ -1245,6 +1245,7 @@ public:
|
||||
~raw_hash_set() { destroy_slots(); }
|
||||
|
||||
iterator begin() {
|
||||
if (empty()) return end();
|
||||
auto it = iterator_at(0);
|
||||
it.skip_empty_or_deleted();
|
||||
return it;
|
||||
|
||||
Reference in New Issue
Block a user