Library of sparse collections and tools for working with them.
$ dotnet add package GPS.CollectionsLibrary of specialized data structures.
IDictionary<TKey, TValue> that guarantees order of data insertion is preserved on the Keys collection and enumerator while maintaining thread-safe inserts and random access.GPS.Collections is available through Nuget.
nuget install GPS.Collections
IDictionary<TKey, TValue> that guarantees order of data insertion is preserved on the Keys collection and enumerator while maintaining thread-safe inserts and random access.
/// <summary>
/// Reorders the data in the collection according the supplied selector,
/// IComparer and ReorderDirection specified.
/// </summary>
/// <param name="selector">Func of the selector.</param>
/// <param name="direction">ReorderDirection specifying the direction
/// to sort the data.</param>
public void Reorder(Func<(TKey Key, TValue Value), TKey> selector
, ReorderDirection direction = ReorderDirection.Ascending) { ... }
/// <summary>
/// Reorders the data in the collection according the supplied selector,
/// IComparer and ReorderDirection specified.
/// </summary>
/// <param name="selector">Func of the selector.</param>
/// <param name="comparer">IComparer instance that performs the test
/// to determine the ordinality of two datum in the collection.</comparer>
/// <param name="direction">ReorderDirection specifying the direction
/// to sort the data.</param>
public void Reorder(Func<(TKey Key, TValue Value), TKey> selector
, IComparer<TKey> comparer
, ReorderDirection direction = ReorderDirection.Ascending) { ... }
| Loading | Positive Random | Open-Ended Random | Find Last | Enumerate | Sum | Memory | |
|---|---|---|---|---|---|---|---|
| MatrixArray | 49 | 67 | 61 | 39 | 24 | 240 | 1494190 |
| Dictionary | 38 | 28 | 28 | 0 | 7 | 101 | 668789 |
| SortedDictionary | 409 | 421 | 464 | 25 | 28 | 1347 | 670201 |
The MatrixArray is an auto-growing array of arrays that provide a contiguous indexing mechanism. At full depth, indices may be any Int32 value, both positive and negative. This allows for natural indexing of data without sliding offsets.
var matrixArray = new MatrixArray<string>();
matrixArray[-1] = "negative one";
matrixArray[-2] = "negative two";
Console.WriteLine($"Range: {matrixArray.Lowest} to {matrixArray.Highest}");
// Range: -2 to -1
var matrixArray = new MatrixArray<string>();
matrixArray[-1000] = "negative one-thousand";
matrixArray[1000] = "one-thousand";
Console.WriteLine($"Range: {matrixArray.Lowest} to {matrixArray.Highest}");
// Range: -1000 to 1000
Console.WriteLine($"Count: {matrixArray.Count}");
// Count: 2001
var matrixArray = new MatrixArray<string>();
matrixArray[-1] = "negative one";
matrixArray[1] = "one";
Console.WriteLine($"Count: {matrixArray.Count}");
// Count: 3
matrixArray[3] = "three";
Console.WriteLine($"Count: {matrixArray.Count}");
// Count: 5
matrixArray[2] = "two";
Console.WriteLine($"Count: {matrixArray.Count}");
// Count: 5
var matrixArray = new MatrixArray<string>();
matrixArray[0] = "zero";
matrixArray.AddRange(new [] { "one", "two" } );
Console.WriteLine($"Range: {matrixArray.Lowest} to {matrixArray.Highest}");
// Range: 0 to 2
var matrixArray = new MatrixArray<string>();
matrixArray.AddRange(21, new [] { "twenty-one", "twenty-two" } );
Console.WriteLine($"Range: {matrixArray.Lowest} to {matrixArray.Highest}");
// Range: 21 to 22
var matrixArray = new MatrixArray<string>();
matrixArray[10] = "find me";
matrixArray.AddRange(new [] { "me too", "me three" } );
Console.WriteLine($"IndexOf: \"find me\" = {matrixArray.IndexOf("find me")}");
// IndexOf: "find me" = 10
Console.WriteLine($"IndexOf: \"me three\" = {matrixArray.IndexOf("me three")}");
// IndexOf: "me three" = 12
LinkedArray was left in the package for backwards compatibility, but there is no
reason to use it for new code. Replacing it with MatrixArray is a simple search-replace
process.