-
-
Notifications
You must be signed in to change notification settings - Fork 141
Complexity of the swap method #60
Comments
Hi @asbai, the swap already is O(1). I took your issue as an opportunity to demonstrate this with nanobench. I've added a benchmark that calculates complexity of swap: robin-hood-hashing/src/test/unit/bench_swap.cpp Lines 18 to 27 in f577ca9
This benchmarks swap() with differently sized maps. It can be clearly seen that swap performance is always constant at 11.27 ns/op:
Additionally, this data can be used to fit different complexity curves to the data. Unsurprisingly, the best fitting curve with an error of only 0.1% is
So no need to worry, swap already is O(1). |
Ok, it's my fault. I'm not noticed that you have a I've only seen the |
According to the standard, the
swap
method of unordered_set and unordered_map should be constantO(1)
. See: https://en.cppreference.com/w/cpp/container/unordered_set/swap and https://en.cppreference.com/w/cpp/container/unordered_map/swapBut it looks like linear
O(N)
complexity in robin_hook?Can it be optimized to
O(1)
complexity? Thanks :-)The text was updated successfully, but these errors were encountered: