Bijective Dictionary / Map in C #

Is there a bijective dictionary in .NET that efficiently stores Key / Values ​​pairs where both keys and values ​​are different, so is bijective mapping possible (i.e. TryGetValue / TryGetKey)? A naive approach would be to have two internal dictionaries: a key value and a dictionary with a value key, but this is not memory efficient.

+3
source share
5 answers

I do not believe in .NET. Depending on the types of keys / values, I am not sure that using two dictionaries is likely to result in a significant loss of efficiency: this is what I would do until I saw a problem based on the fact that it is simple.

, , . , ...

EDIT: :

  • , , Remove ..
+5

, 2 , . , . , . , .

HashSet / HashSet

+2

? 64 , ( ). , .

0

, , , Dictionary.

0

"" .

var source = GetSomeDictionary();
var opposite = source.ToDictionary(x => x.Value, x => x.Key)

, , ... , . : .

But, most likely, you can hold the second dictionary - and want to save time.

0
source

Source: https://habr.com/ru/post/1703577/


All Articles