[][src]Type Definition sparse_bin_mat::SparseBinSlice

type SparseBinSlice<'a> = SparseBinVecBase<&'a [usize]>;

Implementations

impl<'a> SparseBinSlice<'a>[src]

pub fn new(length: usize, positions: &'a mut [usize]) -> Self[src]

Creates a new vector with the given length and list of non trivial positions.

This take a mutable reference to the positions in order to sort them. If you know the positions are sorted, you can instead use new_from_sorted.

Example

let mut positions = vec![2, 0];
let vector = SparseBinSlice::new(5, &mut positions);

assert_eq!(vector.len(), 5);
assert_eq!(vector.weight(), 2);
assert_eq!(vector.non_trivial_positions().collect::<Vec<_>>(), vec![0, 2]);

Panic

Panics if a position is greater or equal to the length.

This example panics
let vector = SparseBinSlice::new(2, &mut [1, 3]);

pub fn new_from_sorted(length: usize, positions: &'a [usize]) -> Self[src]

Creates a new vector with the given length and a sorted list of non trivial positions.

let mut positions = vec![0, 2];
let vector = SparseBinSlice::new_from_sorted(5, &positions);

assert_eq!(vector.len(), 5);
assert_eq!(vector.weight(), 2);

Panics

Panics if the list of positions is unsorted or if a position is greater or equal to the length.

This example panics
let mut positions = vec![2, 0];
let vector = SparseBinSlice::new_from_sorted(5, &positions);