I want to temporary store some mapping data. The mapping is one to one. I saw this was solved in Python by wrapping two dictionaries in one class. In this case the O for getting mapped value would be O(1). I wan't the same thing. Does .Net already have such structure or I have to implement my own with two dictionaries?
Asked
Active
Viewed 415 times
0
-
1A very exact duplicate: http://stackoverflow.com/questions/268321/bidirectional-1-to-1-dictionary-in-c – Daniel Earwicker Jul 04 '09 at 20:13
1 Answers
4
You have to implement it using two dictionaries. There's no built-in type in the base class library that efficiently supports indexing both by key and value.

Mehrdad Afshari
- 414,610
- 91
- 852
- 789
-
-
I can infer that from the need of *two dictionaries in Python*. – Mehrdad Afshari Jul 04 '09 at 19:50
-
Well, if dataset is small, he can simply write a method to do lookup by value. – SolutionYogi Jul 04 '09 at 19:52
-
2If the data set was small he should not have worried about Big-Oh. – Mehrdad Afshari Jul 04 '09 at 19:53
-
Well, that's true. If he wants O(1) solution, he would need two dictionaries. – SolutionYogi Jul 04 '09 at 19:55
-
Yes, I want both key and value indexed and it should be fast too. I guess there is no built in structure if nobody has mentioned it then? – Sergej Andrejev Jul 04 '09 at 20:13
-
Trust me. There isn't. If you're still not convinced, just check out the list of collections yourself. They are all in the "System.Collections" namespace. – Mehrdad Afshari Jul 04 '09 at 20:23