Trait mightrix::RowPrioMatrix
source · pub trait RowPrioMatrix<'a, const R: usize, const C: usize, T> {
// Required methods
fn insert(&mut self, location: (usize, usize), value: T);
fn get(&self, location: (usize, usize)) -> &T;
fn get_mut(&mut self, location: (usize, usize)) -> &mut T;
fn fill_row(&mut self, row: usize, data: &[T]);
fn fill_col(&'a mut self, col: usize, data: &[T]);
fn get_column(&self, col: usize) -> Column<'_, R, C, T>;
fn get_mut_column(&mut self, col: usize) -> ColumnMut<'_, R, C, T>;
fn get_row(&self, row: usize) -> &[T];
fn get_mut_row(&mut self, row: usize) -> &mut [T];
fn apply_all(&mut self, f: fn(_: &mut T));
fn pretty_print(&self);
}Expand description
RowPrioMatrix encapsulates all functionality a matrix has that uses the memory interpretation RowPrio.
Required Methods§
sourcefn insert(&mut self, location: (usize, usize), value: T)
fn insert(&mut self, location: (usize, usize), value: T)
Inserts a value at position (x, y) inside the matrix.
Panics
If the location given is out of bounds in x or y the function panics.
Examples
let mut data = vec![1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4];
let mut reftrix = Reftrix::<4, 4, RowPrio, u8>::from_values(&mut data[..]);
reftrix.insert((3, 1), 0);
assert_eq!(data[13], 0);sourcefn get(&self, location: (usize, usize)) -> &T
fn get(&self, location: (usize, usize)) -> &T
Get a immutable reference to a value in the matrix at location (x, y)
Panics
If the location given is out of bounds in x or y the function panics.
Examples
let mut data = vec![1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4];
let mut reftrix = Reftrix::<4, 4, RowPrio, u8>::from_values(&mut data[..]);
assert_eq!(reftrix.get((0, 2)), &1);sourcefn get_mut(&mut self, location: (usize, usize)) -> &mut T
fn get_mut(&mut self, location: (usize, usize)) -> &mut T
Get a mutable reference to a value in the matrix at location (x, y)
Panics
If the location given is out of bounds in x or y the function panics.
sourcefn fill_row(&mut self, row: usize, data: &[T])
fn fill_row(&mut self, row: usize, data: &[T])
Fills an entire row with the given data.
Panics
If the row is out of bounds.
If the data is not the size of a row.
Examples
let mut data = vec![1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4];
let mut reftrix = Reftrix::<4, 4, RowPrio, u8>::from_values(&mut data[..]);
reftrix.fill_row(1, &[7,7,7,7]);
assert_eq!(&data[4..8], &[7,7,7,7]);sourcefn fill_col(&'a mut self, col: usize, data: &[T])
fn fill_col(&'a mut self, col: usize, data: &[T])
Fills an entire collumn with the given data.
Panics
If the collumn is out of bounds.
If the data is not the size of a collumn.
Examples
let mut data = vec![1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4];
let mut reftrix = Reftrix::<4, 4, RowPrio, u8>::from_values(&mut data[..]);
reftrix.fill_col(1, &[7,7,7,7]);
assert_eq!(data[1], 7);
assert_eq!(data[5], 7);
assert_eq!(data[9], 7);
assert_eq!(data[13], 7);sourcefn get_column(&self, col: usize) -> Column<'_, R, C, T>
fn get_column(&self, col: usize) -> Column<'_, R, C, T>
sourcefn get_mut_column(&mut self, col: usize) -> ColumnMut<'_, R, C, T>
fn get_mut_column(&mut self, col: usize) -> ColumnMut<'_, R, C, T>
sourcefn get_mut_row(&mut self, row: usize) -> &mut [T]
fn get_mut_row(&mut self, row: usize) -> &mut [T]
sourcefn apply_all(&mut self, f: fn(_: &mut T))
fn apply_all(&mut self, f: fn(_: &mut T))
Applies a function on all elements of the matrix.
Examples
let mut data = vec![1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4];
let mut reftrix = Reftrix::<4, 4, RowPrio, u8>::from_values(&mut data[..]);
reftrix.apply_all(|el| *el *= 2);
assert_eq!(&data[..], &[2,2,2,2,4,4,4,4,6,6,6,6,8,8,8,8]);sourcefn pretty_print(&self)
fn pretty_print(&self)
Prints out the matrix, this is only usefull for numeric types.