Is there a data structure that can replace the following two maps:
Dictionary<TypeA, TypeB> map;
Dictionary<TypeB, TypeA> reverse_map;
so that I will always be able to get TypeB from TypaA, and TypeA from TypeB? My current solution requires adding key->value to map 1 and value->key to map 2.
What you need is called a ‘Bidirectional Map’ like Google’s BiMap which is part of Google Collections (java library).
A related SO thread is here. This thread has a simple TwoWayHashmap java implementation posted by me. This uses two Maps to simulate a two-way-map. Although the code is java specific, I think it would be easy to generalize this as a data structure.