I have a data structure that is essentially key-value pairs. However unlike a dictionary I might have duplicate keys, this is legitimate in the system I’m designing. Currently I have a Java class that implements a Pair object (A lot like the example here A Java collection of value pairs? (tuples?)) which has a left and a right (key and value) I then store these in an ArrayList.
What I want is a means of looking up the keys in a fashion quicker that O(N) as the list can grow quite large.
I have thought about potentially creating an inverted index, however wondered whether there is another way?
To handle reduce of a duplicates I really just want to obtain a list of positions in the list based on the key.
Doesn’t have to be in Java – thats just what I’ll be implementing in.
Cheers
David
What are you supposed to get if you ask for the value of a key that exists multiple times? Depending on the answer to that question Apache Commons MultiMap might solve your problem.