Consider unordered_map:
template<
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = std::allocator< std::pair<const Key, T> >
> class unordered_map;
I know (a==b) is faster than !(a<b) && !(b>a), but since unordered_map does not use std::less<Key> to compare/store the keys in the map, I wonder how can an implementation profit by tree data structures in the most efficient way to read/store different keys in the same bucket. It seems that a convertion from Key to a sort of KeyWrapper with operator<() defined cannot be avoided by any implementation with trees.
You cannot use a tree inside
unordered_map, even just within a bucket.unordered_map‘s interface simply does not allow it. The key type is required only to be equality comparable, nothing more. That’s why it’s called an “unordered” map; because there is no specific ordering of elements. To use some kind of binary tree would require a strict weak ordering, which is not required.If you want to use a variation of an
unordered_map, you may. But it would not be anunordered_mapas defined by the standard.