22

I have two sets of objects where in some cases the first set will be used as keys for the other set, and in other cases the second set will be used as keys for the first. In addition there must be no duplicates in either list.

What would be a good data-structure to use for this? Should I use two Dictionaries for this or are there smarter ways?

Svish
  • 152,914
  • 173
  • 462
  • 620
  • 5
    There's a Bidirectional Dictionary implementation by Jon Skeet @ http://stackoverflow.com/questions/255341/getting-key-of-value-of-a-generic-dictionary#255630 . And yes, the standard way to achieve this is to use 2 dictionaries. – Falaina Aug 04 '09 at 14:02

1 Answers1

8

Someone with better knowledge of data structures could probably give better advice, but personally, I'd use 2 dictionaries for ease of use. You could do the same with 1 dictionary but access time would increase.

Edit: crap, I was just in the process of writing up some code how I would do it and I saw that Falaina posted this which is the same idea that I was doing only much better: Getting key of value of a generic Dictionary?

Community
  • 1
  • 1
Dinah
  • 52,922
  • 30
  • 133
  • 149