Skip to main content

Node Array

Layout#

Uncompressed Array
[A,A,A,A,A,A,A,B,B,B,B,C,C,C,C,C,C,C,C,C,C,C]

would be compressed to

CompressedNodeList
[{A, 7},{B, 4},{C, 11}]

Internally a node struct is used

Node
public readonly struct Node {
public int Count { get; }
public T Object { get; }
public Node(int count, T obj) {
Count = count;
Object = obj;
}
}

Usage#

CompressedNodeList has 2 constructors :-

public CompressedArray(T[] data) { }
public CompressedArray(List<Node> data, int size) { }
public CompressedArray(int size) { }

allowing you to create the array from both compressed and uncompressed data

using the third constructor you can create an empty compressed array and fill it using Add() method in essence creating a comppressed array directly without calling the Compress() method


Data Access#

If individual elements need to be accessed it is recomended to do this while array is in Decompressed state, in that case complexity for GetAt() and SetAt() is O(1)

Complexity of GetAt() in Compressed state is O(logn), internally binary search is used.

danger

SetAt() in Compressed state is not implemented yet and will throw an exception if executed.

You can get the length of compressed data using CompressedLength