The C# the generic HashSet<T> search performance should be O(1), and the search performance of an ObservableCollection<T> should be O(n).
I have a large amount of unique elements, each element has a DateTime property that is not unique.
Each element calculates its HashCode by simply returning its DateTime.GetHashCode().
Now I want to get a subset of my data, e.g. all elements that have a date which is between March 2012 and June 2012.
var result = from p in this.Elements
where p.Date >= new DateTime(2012, 03, 01) &&
p.Date <= new DateTime(2012, 30, 06
select p;
If I run this LINQ query on a collection of 300.000 elements, it takes ~25 ms to return 80 elements that are within the given range - it does not matter if I use a HashSet<T> or an ObservableCollection<T>.
If I loop through all elements manually and check them, it takes the same time, ~25 ms.
But I do know the HashCode of all Dates that are within the given range. Is it possible to get all elements with the given HashCodes from my HashSet<T>? I think that would be much faster...
Is it possible to speed up the LINQ query? I assume that it does not make use of the special abilities of my HashSet<T>?