Is there a data structure that has O(1) complexity for value->key lookups?

I was wondering if there is a data structure (probably similar to Map) that has a O(1) complexity both ways.

key → value is covered by fetch but value-> key is not.

If you can afford the mem size, just maintain two copies of map with the inputs swapped?

Ets should also work, just keep key and value as separate fields and do lookup accordingly. Think of it as db columns and just which columns you point your WHERE at.

2 Likes