Is it possible to select efficiently a somewhat random element in abseil::node_hash_map
, or more generally any abseil
map?
For example, I'd be happy with an approach that selected a slot at random, then found the next occupied slot and chose a random element from within the elements hashed to that slot, but it isn't clear this is possible without access to the map internals.
Something like std::next(map, n)
where n
is an integer selected randomly between [0, map.size())
would work but is very slow with complexity O(map.size())
.