Better structure for Looking up booleans for an index?
This is a bit nitpicking and I might have overlooked something simple
Sometimes I have some integers and have to be able to lookup whether they're true or false. I've always solved this by using an Dictionary<int,bool> , inserting a true and just using ContainsKey to see if something is true (it's false by default.)
But it doesn't seem like an elegant solution to insert a bool that isn't even used :) What's structure would you recommend for this? Lookup performance being primary and insertions secondary (but important)
Some nice (LINQ) syntax for having a bunch of indices and returning items that are not contained would be a bonus
Use a HashSet<int> to hold the "true" integers and use Contains to search the collection. With this approach you store just the data you need and you get the same O(1) performance you are currently getting with the dictionary.