Given a generic List I would need some kind of index (in the database sense) that would allow me fast retrieval. The keys for this index would not be unique, so I can’t use a dictionary. Here’s what I have in mind: Given a class Foo { P1, P2, P3 } that may have data like this
{ "aaa", 111, "yes" }
{ "aaa", 112, "no" }
{ "bbb", 111, "no" }
{ "bbb", 220, "yes" }
{ "bbb", 220, "no" }
{ "ccc", 300, "yes" }
I would need to quickly access all the records where P1 is “bbb” (3rd,4th, and 5th) or all the ones where P2 is 111 (1st and 3rd). I could use a sorted List but if I need more than one way of sorting / indexing I would end up with duplicated lists.
Is there something built-in into the .NET framework or maybe an OS library that would do something like this? Thanks.
P.S. I mentioned “sorted List” with the idea that a sorted list will return / find an item much faster. I do not need the list to be necessarily sorted; I’m just looking for fast retrieval / finding.
I’ve never actually had a chance to use it, but you may try i4o. Its supposed to provide indexes for in-memory objects for usage with Linq. You specify the indexes for a class using either attributes or as part of constructing the indexer, then you create an IndexableCollection.
At that point, you just query the collection using Linq, and the indexes work behind the scenes to optomize the access patterns for the data.