It seems like java is doing something smart with its HashMap by oscillating between linked list vs. red-black tree based on the size in the same bucket.
What is the underlying data structure of std::unordered_map? Is it also doing something smart?
It seems like java is doing something smart with its HashMap by oscillating between linked list vs. red-black tree based on the size in the same bucket.
What is the underlying data structure of std::unordered_map? Is it also doing something smart?
I don't think this is specified as part of the standard, but from g++9 implementation we could see:
# grep -A 3 hashtable.*aggregation /usr/include/c++/9/bits/hashtable.h
* In terms of Standard containers the hashtable is like the aggregation of:
*
* - std::forward_list<_Node> containing the elements
* - std::vector<std::forward_list<_Node>::iterator> representing the buckets
It is just a vector
of forward_list
, not as "smart" as Java HashMap