Bidirectional Dictionary?

I have two sets of objects, where in some cases the first set will be used as keys for another set, and in other cases the second set will be used as keys for the first. In addition, in any list should not be duplicates.

What would be a good data structure for this? Should I use two dictionaries for this or are there more reasonable ways?

+19
c # data-structures
Aug 04 '09 at 13:56
source share
3 answers

Someone who is better versed in data structures can probably give better advice, but personally I would use 2 dictionaries for ease of use. You can do the same with 1 dictionary, but access time will increase.

Edit : shit, I just wrote the code, how would I do it, and I saw that Falaina posted this, which is the same idea that I did only much better: Getting the key from the shared dictionary?

+8
Aug 04 '09 at 13:58
source share

This is usually called a bidirectional map. If you don't like PowerCollections, there is a special implementation here: 1-to-1 Bidirectional Dictionary in C #

+2
Feb 28 2018-12-28T00:
source share

There are several multicade collections. Try:

http://powercollections.codeplex.com/

or

http://www.codeproject.com/KB/recipes/multikey-dictionary.aspx

Wintellect's energy source collections are probably a great place to start. They have a proven MultiDictionary as part of their package.

+1
Aug 04 '09 at 14:08
source share



All Articles