An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Sparse Collections

[![NuGet version (SoftCircuits.SparseCollections)](https://img.shields.io/nuget/v/SoftCircuits.SparseCollections.svg?style=flat-square)](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);
```