Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bi-directional dictionary? [duplicate]

Tags:

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?

like image 736
Svish Avatar asked Aug 04 '09 13:08

Svish


1 Answers

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?

like image 143
Dinah Avatar answered Oct 07 '22 00:10

Dinah