Dictionary-like data structure representing a bijective map?

Does anyone know of a dictionary-like data structure that represents a bijective (one-to-one and onto) map? And if so, is there a Julia implementation of such a data structure?

Ideally this data structure would have a method for getting a key given a value (in addition to the usual method for getting a value given a key).

So the interface might look something like this:

julia> b = BijectiveMap(:a => 1);

julia> get_value(b, :a)
1

julia> get_key(b, 1)
:a
1 Like

I found one!

https://github.com/scheinerman/Bijections.jl

For reference, here’s the syntax used by Bijections.jl:

julia> b = Bijection(:a, 1)
Bijection{Symbol,Int64} (with 1 pairs)

julia> b[:a]
1

julia> b(1)
:a
6 Likes