Now, before you scold me, I know there's a very similar question:
Best data structure for two way mapping?
In fact, I am looking for a data structure that will accomplish the same thing. Specifically, I have a string that should be mapped to another string, and that other string should also be mapped to the original string.
For instance:
".jpg" -> "image/jpeg"
"image/jpeg" -> ".jpg"
The linked question suggest the use of some kind of hashmap or Dictionary<string,string>
to accomplish this.
One would have a custom data type that will hold two dictionaries, each dictionary being one way of mapping. This will provide with O(1), but i find it not scalable at all.
Considering that I have a Dictionary with all the mappings from 200 MIME types to the associated file extension, I would need to create a similar one, with the same content but inversed. This is very prone to typos, or missing keys, and is a lot of duplicated code.
Although the linked question aims for a solution in Java, I am looking for a solution in C#.
Is there a .NET data structure that supports these kind of two way mapping between objects?
If there is not, how can I accomplish this without replicating code (as in the two dictionaries solution)?