https://github.com/softcircuits/sparsecollections
The SparseCollections library provides the SparseArray<T> and SparseMatrix<T> collection classes.
https://github.com/softcircuits/sparsecollections
sparce-array sparse sparse-data sparse-matrices sparse-matrix
Last synced: 7 months ago
JSON representation
The SparseCollections library provides the SparseArray<T> and SparseMatrix<T> collection classes.
- Host: GitHub
- URL: https://github.com/softcircuits/sparsecollections
- Owner: SoftCircuits
- License: mit
- Created: 2019-07-08T16:28:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-02T23:58:39.000Z (10 months ago)
- Last Synced: 2025-06-09T05:56:02.234Z (7 months ago)
- Topics: sparce-array, sparse, sparse-data, sparse-matrices, sparse-matrix
- Language: C#
- Size: 29.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
- License: License.txt
Awesome Lists containing this project
README
# Sparse Collections
[](https://www.nuget.org/packages/SoftCircuits.SparseCollections/)
```
Install-Package SoftCircuits.SparseCollections
```
## Overview
The SparseCollections library includes two lightweight collection classes, `SparseArray` and `SparseMatrix`. The array class allows statements such as `array[1000000] = 5` and `array[-1000000] = 6` without having to allocate a large array. The matrix class works similarly except as a two-dimensional array.
## Examples
This example adds two items to a `SparseArray` and confirms their value.
```cs
SparseArray array = new SparseArray();
// Assign some values
array[10000] = 4;
array[-100000] = 5;
// Confirm values
Debug.Assert(array[10000] == 4);
Debug.Assert(array[-100000] == 5);
```
This example does the same thing with a `SparseMatrix`.
```cs
SparseMatrix matrix = new SparseMatrix();
// Assign some values
matrix[10000, -10000] = 4;
matrix[-100000, 20000] = 5;
// Confirm values
Debug.Assert(matrix[10000, -10000] == 4);
Debug.Assert(matrix[-100000, 20000] == 5);
```