i have a set of pairs of data: (key, value). they key is unique, and so is the value (there will not be two equal values, nor two equal keys). Like this...
dataStructure = {"ph", 0}, {"f", 1}, {"o", 2}, {"th", 3} ...
(the index is arbitrary, but it must be accessible)
is there any data structure that (efficiently) allows me to retrieve the key of an item, given a value? like this:dataStructure.getByValue("ph") -> 0 and dataStructure.getByKey(0) -> "ph"
I've been reading about hashmaps, but this is not the structure i'm looking for: hashmaps are for non-unique value items, so i can't retrieve the key given a value.
I'd like to use this as a codifier, "photho" would be codified into 0230, and this would be decodified as "photho" again.
I'd like to know the name of the data structure... it doesn't matter the language...


Check Solution