In erlang orddict, it is known that fetch(Key, Orddict)
returns the value associated with Key. My question is can we do it in vise-versa? i.e., can return the key associated with a known value placed a varible?
There is no efficient way to do that, other than by iterating all key/value pairs.
To do that efficiently you need an index on the value field. That index will map values to the set of keys that bind to those values.
The standard library does not provide this, but you can build it yourself.
How to iterate over key/value pairs please?
Inefficiently. For example, this way:
KeysWithValueEqualsTo1 = orddict:filter(fun (K, V) -> V =:= 1 end, OriginalOrdDict).
1 Like