Crate mightrix

Source
Expand description

§mightrix

The mightrix crate exposes matrix types that let continuous memory be used as if it where a matrix. The dimensions of the matrix is asserted through const generics. This way the owned variant of the matrix Stacktrix can use a fixed size array on the stack.

§Example

use mightrix::{ Reftrix, ColumnPrio, ColumnPrioMatrix };

fn main() {
    let mut data = vec![1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4];

    let mut matrix = Reftrix::<4, 4, ColumnPrio, u8>::from_values(&mut data[..]);

    for el in matrix.get_mut_row(0) {
        *el *= 2;
    }


    for col in matrix.cols_mut() {
        for (i, cell) in col.into_iter().enumerate() {
            *cell += i as u8;
        }
    }
    assert_eq!(&data[..], &[2, 2, 3, 4, 4, 3, 4, 5, 6, 4, 5, 6, 8, 5, 6, 7]);
}

Matrix before:

Col0Col1Col2Col3
Row01234
Row11234
Row21234
Row31234

Matrix after:

Col0Col1Col2Col3
Row02468
Row12345
Row23456
Row34567

This library does not aim to be a math library and therefore does not implement common matrix operations, though they might be implemented over time.

This crate is currently used to implement the aes algorithm. In that algorithm the state is represented as a column first ColumnPrio matrix, and all operations are done on that Matrix.

Currently there are two matrix types:

  • Reftrix: This matrix uses a mutable slice and therefore manipulates the data directly.

  • Stacktrix: This matrix copies the data and uses a fixed size array on the stack, this way the original data is not manipulated.

Structs§

ColumnPrio
Matrices (Reftrix, Stacktrix) with Columnprio use a column first memory representation.
IntermittentSlice
The IntermittentSlice struct represents a imutable matrix row or col in ColumnPrio / RowPrio matrices.
IntermittentSliceMut
The IntermittentSliceMut struct represents a mutable matrix row or col in all ColumnPrio / RowPrio matrices.
IterIntermittentSlices
IterIntermittentSlice represents an iterator over all rows / cols in a ColumnPrio / RowPrio Matrix.
IterMutIntermittentSlices
IterIntermittentSliceMut represents an mutable iterator over all rows / cols in a ColumnPrio / RowPrio Matrix.
IterSlices
IterRows represents an iterator over all rows of a Matrix.
IterSlicesMut
IterRows represents an iterator over all rows of a Matrix.
Reftrix
Reftrix allows a mutable slice to be used as a Matrix.
RowPrio
Matrices (Reftrix, Stacktrix) with RowPrio use a row first memory representation.
Stacktrix
Stacktrix allows a stack based array to be used as a Matrix.

Traits§

ColumnPrioMatrix
ColumnPrioMatrix encapsulates all functionality a matrix has that uses the memory interpretation ColumnPrio.
RowPrioMatrix
RowPrioMatrix encapsulates all functionality a matrix has that uses the memory interpretation RowPrio.