Bijections
Overview
Mathematically, a bijection is a one-to-one and onto function between sets. In this module, we provide the Bijection
data type that represents a bijection between finite collections of objects.
A Dict
in Julia is not one-to-one. Two different keys might have the same value. A Bijection
data structure behaves just like a Dict
except that it prevents assigning the same value to two different keys.
Getting started
After using Bijections
we create a new Bijection
in one of the following ways:
b = Bijection()
: This gives a newBijection
in which the keys and values are ofAny
type.b = Bijection{S,T}()
: This gives a newBijection
in which the keys are of typeS
and the values are of typeT
.b = Bijection(x,y)
: This gives a newBijection
in which the keys are typetypeof(x)
, the values are typetypeof(y)
and the key-value pair(x,y)
is inserted into theBijection
.b = Bijection(dict::AbstractDict{S, T})
: This gives a newBijection
in which the keys are typeS
, the values are typeT
and all key-value pairs indict
are inserted into theBijection
.b = Bijection(pair_list::Vector{Pair{S, T}})
: Create a newBijection
using a list of pairs.
See also the Mutable Objects page for additional constructor options.