I have ID values of the type unsigned int
. I need to map an Id to a pointer in constant time.
Key Distribution:
ID will have a value in the range of 0 to uint_max. Most of keys will be clustered into a single group, but there will be outliers.
Implementation:
I thought about using the C++ ext hash_map stuff, but I've heard their performance isn't too great when keys have a huge potential range.
I've also thought of using some form of chained lookup (equivalent to recursively subdividing the range into C chucks). If there are no keys in a range, that range will point to NULL.
N = Key Range
Level 0 (divided into C = 16, so 16 pieces) = [0, N/16), [N/16, 2*(N/16)), ...
Level 1 (divided into C = 16, so 16 * 16 pieces) = ...
Does anyone else have ideas on how this mapping can be more efficiently implemented?
Update:
By constant, I just meant each key lookup is not significantly influenced by the # of values in the item. I did not mean it had to be a single op.