Enhanced C#
Language of your choice: library documentation

A bijection is a onetoone function and its inverse. It is implemented with a pair of dictionaries, one that maps K1 to K2 and another that maps K2 to K1. More...
A bijection is a onetoone function and its inverse. It is implemented with a pair of dictionaries, one that maps K1 to K2 and another that maps K2 to K1.
K1  Default key. 
K2  Inverse key. 
The Bijection object that you first create is a dictionary from K1 to K2. Call the Inverse property to get the inverse dictionary from K2 back to K1. Whenever you modify one of the dictionaries, the other dictionary is also modified in the same way.
For example, if you do this:
Then the bijection will contain three pairs: {1, "one"}, {3, "three"}
and {4, "four"}
. The inverse bijection object map.Inverse is "first
class" and can be used just like the original map. The two interfaces, map
and map.Inverse
, are linked to each other, so map.Inverse.Inverse == map
.
This collection itself is not safe for multithreaded access, even if it is constructed out of two ConcurrentDictionary{K,V} objects.
Properties  
Bijection< K2, K1 >  Inverse [get] 
Returns the inverse dictionary. Note: this.Inverse.Inverse == this . More...  
ICollection< K1 >  Keys [get] 
ICollection< K2 >  Values [get] 
K2  this[K1 key] [get, set] 
int  Count [get] 
bool  IsReadOnly [get] 
Public Member Functions  
Bijection ()  
Constructs a bijection out of two Dictionary<TKey,TValue> objects. More...  
Bijection (int capacity)  
Constructs a bijection out of two Dictionary<TKey,TValue> objects, each with the specified capacity. More...  
Bijection (IReadOnlyCollection< KeyValuePair< K1, K2 >> input)  
Constructs a bijection out of two Dictionary<TKey,TValue> objects, copying the specified initial contents, and using the initial Count as the capacity. More...  
Bijection (IEnumerable< KeyValuePair< K1, K2 >> input, int capacity=0)  
Constructs a bijection out of two Dictionary<TKey,TValue> objects, copying the specified initial contents. More...  
Bijection (IDictionary< K1, K2 > cur, IDictionary< K2, K1 > inv)  
Constructs a bijection out of two existing dictionaries. More...  
void  Add (K1 key, K2 value) 
bool  ContainsKey (K1 key) 
bool  Remove (K1 key) 
bool  TryGetValue (K1 key, out K2 value) 
void  Add (KeyValuePair< K1, K2 > item) 
void  Clear () 
bool  Contains (KeyValuePair< K1, K2 > item) 
void  CopyTo (KeyValuePair< K1, K2 >[] array, int arrayIndex) 
bool  Remove (KeyValuePair< K1, K2 > item) 
IEnumerator< KeyValuePair< K1, K2 > >  GetEnumerator () 
Protected Member Functions  
Bijection (IDictionary< K1, K2 > cur, Bijection< K2, K1 > other)  

inline 
Constructs a bijection out of two Dictionary<TKey,TValue> objects.

inline 
Constructs a bijection out of two Dictionary<TKey,TValue> objects, each with the specified capacity.

inline 
Constructs a bijection out of two Dictionary<TKey,TValue> objects, copying the specified initial contents, and using the initial Count as the capacity.
KeyAlreadyExistsException  The input had a duplicate key or value. 
The bijection is mutable even though the input is not.

inline 
Constructs a bijection out of two Dictionary<TKey,TValue> objects, copying the specified initial contents.
KeyAlreadyExistsException  The input had a duplicate key or value. 

inline 
Constructs a bijection out of two existing dictionaries.
To save time, the constructor does not verify that the two dictionaries are a proper bijection; instead it works "on the honor system", and only checks to ensure that the two dictionaries have the same Count
. The two dictionaries must already be a bijection (onetoone maps into each other) and should not be modified after they are attached to this object. Of course, you can supply two empty dictionaries of any type.

get 
Returns the inverse dictionary. Note: this.Inverse.Inverse == this
.