Data structure for enumeration in C # where search is often based on a single property of stored objects

I'm wondering what the Data Structure people recommend doing the following. I have a class that has three main properties, eg.

public class Example {

  public Object One { get; }
  public Object Two { get; }
  public Object Three { get; }
}

      

Another class contains a collection of these objects and often needs to be enumerated over them, which I do mainly with LINQ. A lot of time, although I only need to search / list a subset of these objects based mainly on the value of the One property, so I would like to store them in an efficient data structure based on that property. I could do something like the following:

Dictionary<Object,List<Example>>

      

But this seems very inefficient to me, I know I need some kind of Hash table, but I have never used it before in C #. I don't know what you need to use.

Some other requirements / notes:

  • All objects are immutable and have fixed hash codes that are calculated from the values ​​that the class instance receives in the constructors
  • It should be possible to store multiple elements having the same value (and therefore hash code) for a property. One in the same slot in the data structure.
  • Should be able to freely add and remove objects from the collection
+1


a source to share


3 answers


PowerCollections ( http://www.codeplex.com/PowerCollections ) has a MultiDictionary container - maybe you could try this?



+1


a source


Indexed LINQ can help you here. It provides an in-memory assembly, but allows property attributes on your objects to be indexable so that they can make efficient queries against them.



+2


a source


or HybridDictionary

0


a source







All Articles