Good data structure for efficient insert/querying on arbitrary properties

Posted by Juliet on Stack Overflow See other posts from Stack Overflow or by Juliet
Published on 2010-03-18T21:25:56Z Indexed on 2010/03/18 21:31 UTC
Read the original article Hit count: 275

Filed under:
|

I'm working on a project where Arrays are the default data structure for everything, and every query is a linear search in the form of:

  • Need a customer with a particular name? customer.Find(x => x.Name == name)
  • Need a customer with a particular unique id? customer.Find(x => x.Id == id)
  • Need a customer of a particular type and age? customer.Find(x => x is PreferredCustomer && x.Age >= age)
  • Need a customer of a particular name and age? customer.Find(x => x.Name == name && x.Age == age)

In almost all instances, the criteria for lookups is well-defined. For example, we only search for customers by one or more of the properties Id, Type, Name, or Age. We rarely search by anything else.

Is a good data structure to support arbitrary queries of these types with lookup better than O(n)? Any out-of-the-box implementations for .NET?

© Stack Overflow or respective owner

Related posts about c#

Related posts about data-structures