invoke

open operator override fun <T> invoke(original: SparseMatrix<T>): SparseMatrix<T>

Create a copy of the parameter using the copyOf member function.

Return

The copy (from copyOf), depending on the type this may be the same object as the original.

Parameters

original

The matrix to create a copy of


open operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, initValue: T, validator: (Int, Int) -> Boolean): SparseMatrix<T>

Create a sparse matrix that has the given maximum X and Y values, is initialized with the parameter value, and uses the function to determine whether the cell exists. The returned matrix is immutable, but the validator is not required to always return the same value.

Return

The resulting matrix.

Parameters

maxWidth

The maximum width of the matrix

maxHeight

The maximum height of the matrix

initValue

The value for each cell in the matrix.

validator

Function that determines whether the cell at the given coordinates exists.


open inline operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, noinline validator: (Int, Int) -> Boolean, init: (Int, Int) -> T): SparseMatrix<T>

Create a sparse matrix that has the given maximum X and Y values, has the given validator to determine sparseness and uses the given function to initialize the matrix (values set on construction).

Return

The resulting matrix.

Parameters

maxWidth

The width of the matrix

maxHeight

The height of the matrix

validator

A function that is used to determine whether a particular coordinate is contained in the matrix.

init

An initialization function that sets the values for the matrix.


open inline operator override fun <T> invoke(maxWidth: Int, maxHeight: Int, init: SparseMatrix.SparseInit<T>.(Int, Int) -> SparseMatrix.SparseValue<T>): SparseMatrix<T>

Create a sparse matrix with given maximum X and Y that is initialized using the given "constructor" function. This function invokes the initializer on construction only.

Example (creating a matrix with a hole in the middle):

val donut = SparseMatrix(3, 3) { x, y ->
when {
y == 0 -> value(x + 1)
y == 2 -> value(7-x)
x == 0 -> value(8)
x == 2 -> value(4)
else -> sparse
}
}

Return

A matrix initialized according to the init function

Parameters

maxWidth

The width of the matrix

maxHeight

The height of the matrix

init

The function used to initialize the matrix.