I have a large collection of objects
public class Restriction { // which days this restriction applies to public DateTime From { get; set; } public DateTime To { get; set; } // valid applicable restriction range public int Minimum { get; set; } public int Maximum { get; set; } }
Then i could
IList<Restricton> restrictions;
and then search for restrictions applied on a specific day
restrictions.Where(r => day >= r.From && day <= r.To);
Problem
I believe that using IList<T> not the best option, because I will fulfill many requests for these restrictions, and every time I call the LINQ .Where method, the whole collection will be enumerated and filtered.
From SQL knowledge, I know that table scans are always worse than index scans, so I would like to apply the same logic here. Instead of listing the entire collection every time I prefer to filter in a more reasonable way.
Question
What would be better ( faster ) to list my limitations so that my algorithm does not re-read them every time I would like to filter out a few?
I was thinking about IDictionary<K,V> , but still it was necessary to scan them all, because my restrictions were not set per day, but rather in the daily range.
What would you suggest?
source share