I am on search for a datastucture that allows me to search for keys and values also. Quite now I´m using a simple dictionary for that, but if I search for values within it I have to loop all keys (having O(n) if I´m right). But since my map is quite small (having just 5 entries) I´m not sure if this would matter anyway.
Dictionary<string, int> myDict = new Dictionary<string, int> {
{"first", 1},
{"second", 2},
{"third", 3},
{"fourth", 4},
{"fifth", 5}
}
Now accessing the map by key is easy:
var myInt = myDict["second"]; // O(1)
But because I need to access this map quite often (for keys and values) I´m not sure if there is a better way to store the values then this:
var myString = myDict.Single(x => x.Value == 2).Key; // O(n)