CompactArrayMutableSparseMatrix

Implementation of a MutableSparseMatrix based upon an array to store data and validity. It uses the same array to record sparseness as well as data. It does not support changing validity of cells (at this point).

Constructors

Link copied to clipboard
constructor(maxWidth: Int, maxHeight: Int, initValue: T, validator: (Int, Int) -> Boolean)

Create a new instance of the class with the given validation function. All elements of the matrix will be set to the same initial value. The validation function does not need to validate that the coordinate is within

constructor(original: CompactArrayMutableSparseMatrix<T>)

Create a new instance that is a copy of the original matrix. This will be a shallow copy as in the elements will not be copied.

constructor(source: Matrix<SparseMatrix.SparseValue<T>>)

A constructor that creates a new CompactArrayMutableSparseMatrix given a matrix of SparseValues. Those are used to initialize the matrix.

Types

Link copied to clipboard
object Companion

The companion object contains factory functions to create new instances with initialization.

Properties

Link copied to clipboard

Get an iterable with all valid indices in the matrix

Link copied to clipboard
open override val maxHeight: Int

The maximum x coordinate that is valid

Link copied to clipboard
open override val maxWidth: Int

The maximum x coordinate that is valid which can be stored.

Link copied to clipboard
open override val validator: (Int, Int) -> Boolean

For copying allow retrieving the/a validator function

Functions

Link copied to clipboard
open fun asSequence(): Sequence<T>

Get all elements in the matrix as sequence.

Link copied to clipboard
open fun contentEquals(other: SparseMatrix<*>): Boolean

Determine whether the content of this matrix is the same as the other by checking equality on the cell values. Sparse matrices with different dimensions, but the same valid indices can be equal.

Link copied to clipboard

Create a copy of this matrix

Link copied to clipboard
open fun fill(value: T)

Helper function to set values

Link copied to clipboard
inline fun <T> MutableSparseMatrix<T>.fill(setter: (Int, Int) -> T)

Helper function to set values into a MutableSparseMatrix.

Link copied to clipboard
open fun forEach(p0: Consumer<in T>)
Link copied to clipboard
inline fun <T> SparseMatrix<T>.forEach(action: (T) -> Unit)

Perform the action for each value in the (sparse) matrix.

Link copied to clipboard
inline fun SparseMatrix<*>.forEachIndex(action: (Int, Int) -> Unit)

Perform the action for each index in the (sparse) matrix. This skips sparse indices.

Link copied to clipboard
open operator override fun get(x: Int, y: Int): T
open operator fun get(pos: Coordinate): T

Whatever the actual type, allow them to be read to read any value. Implementations are expected to use more precise return types.

Link copied to clipboard
open override fun isValid(x: Int, y: Int): Boolean

Determine whether a given coordinate is valid for the matrix.

open fun isValid(pos: Coordinate): Boolean

This function can be used to determine whether the given coordinates are valid. Returns true if valid. This function works on any value for the coordinates and should return false for all values out of range (x<0 || x>=[maxWidth]), (y<0 || y>=[maxHeight]).

Link copied to clipboard
open operator override fun iterator(): Iterator<T>

Get an iterator over all elements in the (sparse) matrix.

Link copied to clipboard
inline fun <T, R> SparseMatrix<T>.map(transform: (T) -> R): SparseMatrix<R>

A map function that creates a new (sparse) matrix with each cell mapped by transform.

Link copied to clipboard
inline fun <T> SparseMatrix<T>.mapBoolean(transform: (T) -> Boolean): SparseBooleanMatrix

A map implementation that creates a boolean sparse matrix based upon the receiver and the transformation function.

Link copied to clipboard
inline fun <T> SparseMatrix<T>.mapInt(transform: (T) -> Int): SparseIntMatrix

Create a new SparseIntMatrix with the dimensions of the original where the value of each cell is the result of applying the transform to the value of the cell in the original.

Link copied to clipboard
open operator override fun set(x: Int, y: Int, value: T)
open operator fun set(pos: Coordinate, value: T)

Set a specific value in the matrix

Link copied to clipboard
Link copied to clipboard
open override fun toString(): String