#Hash map with duplicate keys

1 messages · Page 1 of 1 (latest)

viral isle
#

Is there a way to allow duplicate keys with different values in std.HashMap or std.ArrayHashMap and get an iterator to those values in O(1)? I'd like to avoid the overhead of ArrayList since my duplicate distribution is heavily weighted towards 0.

Right now the only way I see is to hash the string key AND value to insert duplicates. But then using getCtx with will fetch duplicates in O(n) rather than my desired O(1).

I'd like to avoid implementing my own hash map with chaining...

thorn moss
#

Is there anything stopping you from having a hashmap where the value is a linked list of values at that key?

#

which would get you a hash map with chaining but also ensure your chain of values is always specific to that value