Is there a bijective dictionary in.NET that efficiently stores Key/Values pairs, where both keys and values are distinct, so a bijective mapping (i.e. TryGetValue/TryGetKey) is possible? The naive approach would be to have two internal dictionaries: A key-value and a value-key dictionary, but this is not efficient in terms of memory.
I don't believe there's one in .NET. Depending on the key/value types, I'm not sure that using two dictionaries is likely to cause that much of an efficiency loss: it's what I'd do until I saw a problem, based on the fact that it's simple.
In fact, it's very simple as I've already implemented it in another Stack Overflow answer. I'll see if I can find it...
EDIT: I found two:
Essentially you want 2 Sets that reference the same binary element. You will always have the overhead of the references to both elements, but you'd have that either way. Each set would need a different comparer, but that's little overhead. Since you referencing the same element, in both set, you don't have 2 copies.
HashSet HashSet Methods/Members
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With