LINQ Operators |
[This is preliminary documentation and is subject to change.]
The Condensed Library provides a set of specialized LINQ operators that can be much more efficient with large collections than the standard ones provided by System.Linq.
To use the specialized extension methods, add a "using Condensed.Linq;" statement to your source files that need to use them:
using System; using Condensed; using Condensed.Linq; class Program { static void Main() { // Add 100 million dates spanning December 2016: var cc = new CondensedCollection<DateTime>(capacity: 100000000); for (int i = 0; i < 100000000; i++) cc.Add(new DateTime(2016, 12, i % 30 + 1)); // Count the Tuesdays in our collection: var tuesCount = cc.Count(d => d.DayOfWeek == DayOfWeek.Tuesday); // 13,333,333 } }
In addition to memory savings, LINQ operators are a core part of the collection's value proposition. The Count call in the sample above takes approximately 0.002 seconds to run on a 2015 laptop. The same logic takes over 5 seconds to execute against an ordinary List<T> collection. Specialized operators take advantage of the CondensedCollection's built-in knowledge of unique values and internal reference counting to improve the performance of many LINQ operations.
The trade-off is that loading the CondensedCollection typically takes anywhere from 2-10x longer than loading an ordinary List<T>, depending on the type and the quality of its equality comparer.
The following operators are currently supported in the initial alpha release, with more on way:
All
Any
Average
Contains
Count
Distinct
First
FirstOrDefault
Last
LastOrDefault
Max
Min
Sum