A bijection is a one-to-one 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 one-to-one 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.
- Template Parameters
-
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:
var map = new Bijection<int,string>() { { 1, "one" }, {2, "two"} };
map.Add(3, "three");
map.Inverse.Add("four", 4);
map.Inverse.Remove("two");
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.
|
| 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 () |
|