Struct block_grid::BlockGrid[][src]

pub struct BlockGrid<T, B: BlockDim> { /* fields omitted */ }

A fixed-size 2D array with a blocked memory representation.

See crate-level documentation for general usage info.

Implementations

impl<T, B: BlockDim> BlockGrid<T, B>[src]

pub fn from_raw_vec(rows: usize, cols: usize, elems: Vec<T>) -> Result<Self, ()>[src]

Constructs a BlockGrid<T, B> by consuming a Vec<T>.

The ordering of the memory is taken as is in the vector.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

pub fn take_raw_vec(self) -> Vec<T>[src]

Converts a BlockGrid<T, B> to a Vec<T> in memory order.

pub fn rows(&self) -> usize[src]

Returns the nuumber of rows.

pub fn cols(&self) -> usize[src]

Returns the number of columns.

pub fn size(&self) -> usize[src]

Returns the number of elements.

pub fn row_blocks(&self) -> usize[src]

Returns the number of blocks in the vertical direction.

pub fn col_blocks(&self) -> usize[src]

Returns the number of blocks in the horizontal direction.

pub fn blocks(&self) -> usize[src]

Returns the total number of blocks.

pub fn contains(&self, (row, col): Coords) -> bool[src]

Returns true if the given coordinates are valid.

pub fn get(&self, coords: Coords) -> Option<&T>[src]

Returns a reference to the element at the given coordinates, or None if they are out-of-bounds.

pub fn get_mut(&mut self, coords: Coords) -> Option<&mut T>[src]

Returns a mutable reference to the element at the given coordinates, or None if they are out-of-bounds.

pub unsafe fn get_unchecked(&self, coords: Coords) -> &T[src]

Returns a reference to the element at the given coordinates, without bounds checking.

Safety

Calling this method with out-of-bounds coordinates is undefined-behaviour.

pub unsafe fn get_unchecked_mut(&mut self, coords: Coords) -> &mut T[src]

Returns a mutable reference to the element at the given coordinates, without bounds checking.

Safety

Calling this method with out-of-bounds coordinates is undefined-behaviour.

pub fn raw(&self) -> &[T][src]

Borrow BlockGrid<T, B> as a slice in memory order.

pub fn raw_mut(&mut self) -> &mut [T][src]

Mutably borrow BlockGrid<T, B> as a mutable slice in memory order.

pub fn each_iter(&self) -> EachIter<'_, T, B>

Notable traits for EachIter<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for EachIter<'a, T, B> type Item = &'a T;
[src]

Returns an iterator over all the elements in memory order.

If you wanna visit each element arbitrarily, this would be the best way. If you also need coordinates while iterating, follow up with a chained .coords() call.

pub fn each_iter_mut(&mut self) -> EachIterMut<'_, T, B>

Notable traits for EachIterMut<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for EachIterMut<'a, T, B> type Item = &'a mut T;
[src]

Returns a mutable iterator over all the elements in memory order.

If you wanna mutably visit each element arbitrarily, this would be the best way. If you also need coordinates while iterating, follow up with a chained .coords() call.

pub fn block_iter(&self) -> BlockIter<'_, T, B>

Notable traits for BlockIter<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for BlockIter<'a, T, B> type Item = Block<'a, T, B>;
[src]

Returns an iterator over all blocks in memory order, yielding Blocks.

If you need the block coordinates while iterating, follow up with a chained .coords() call. In this case, note that the 2D coordinates yielded are of the actual entire block. If you instead need the coordinates of the first (top-left) element in the block, see Block::starts_at.

pub fn block_iter_mut(&mut self) -> BlockIterMut<'_, T, B>

Notable traits for BlockIterMut<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for BlockIterMut<'a, T, B> type Item = BlockMut<'a, T, B>;
[src]

Returns a mutable iterator over all blocks in memory order, yielding BlockMuts.

If you need the block coordinates while iterating, follow up with a chained .coords() call. In this case, note that the 2D coordinates yielded are of the actual entire block. If you instead need the coordinates of the first (top-left) element in the block, see BlockMut::starts_at.

pub fn row_major_iter(&self) -> RowMajorIter<'_, T, B>

Notable traits for RowMajorIter<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for RowMajorIter<'a, T, B> type Item = &'a T;
[src]

Returns an iterator over all the elements in row-major order.

This ordering is what you're probably used to with usual 2D arrays. This method may be useful for converting between array types or general IO. If you also need the coordinates while iterating, follow up with a chained .coords() call.

pub fn row_major_iter_mut(&mut self) -> RowMajorIterMut<'_, T, B>

Notable traits for RowMajorIterMut<'a, T, B>

impl<'a, T, B: BlockDim> Iterator for RowMajorIterMut<'a, T, B> type Item = &'a mut T;
[src]

Returns an mutable iterator over all the elements in row-major order.

If you also need the coordinates while iterating, follow up with a chained .coords() call.

impl<T: Clone, B: BlockDim> BlockGrid<T, B>[src]

pub fn filled(rows: usize, cols: usize, elem: T) -> Result<Self, ()>[src]

Constructs a BlockGrid<T, B> by filling with a single element.

Errors

If rows and cols do not divide evenly into the block size B.

pub fn from_row_major(rows: usize, cols: usize, elems: &[T]) -> Result<Self, ()>[src]

Constructs a BlockGrid<T, B> from a slice in row-major order.

This method may be useful for converting from a typical 2D array.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

pub fn from_col_major(rows: usize, cols: usize, elems: &[T]) -> Result<Self, ()>[src]

Constructs a BlockGrid<T, B> from a slice in column-major order.

2D arrays are not usually stored like this, but occasionally they are.

Errors

If invalid dimensions, either because rows and cols do not divide evenly into the block size B or the length of elems does not match rows * cols.

impl<T: Clone + Default, B: BlockDim> BlockGrid<T, B>[src]

pub fn new(rows: usize, cols: usize) -> Result<Self, ()>[src]

Constructs a BlockGrid<T, B> by filling with the default value of T.

Errors

If rows and cols do not divide evenly into the block size B.

Trait Implementations

impl<T: Clone, B: Clone + BlockDim> Clone for BlockGrid<T, B>[src]

impl<T: Debug, B: Debug + BlockDim> Debug for BlockGrid<T, B>[src]

impl<T: Eq, B: Eq + BlockDim> Eq for BlockGrid<T, B>[src]

impl<T: Hash, B: Hash + BlockDim> Hash for BlockGrid<T, B>[src]

impl<T, B: BlockDim> Index<(usize, usize)> for BlockGrid<T, B>[src]

type Output = T

The returned type after indexing.

impl<T, B: BlockDim> IndexMut<(usize, usize)> for BlockGrid<T, B>[src]

impl<T: PartialEq, B: PartialEq + BlockDim> PartialEq<BlockGrid<T, B>> for BlockGrid<T, B>[src]

impl<T, B: BlockDim> StructuralEq for BlockGrid<T, B>[src]

impl<T, B: BlockDim> StructuralPartialEq for BlockGrid<T, B>[src]

Auto Trait Implementations

impl<T, B> Send for BlockGrid<T, B> where
    B: Send,
    T: Send
[src]

impl<T, B> Sync for BlockGrid<T, B> where
    B: Sync,
    T: Sync
[src]

impl<T, B> Unpin for BlockGrid<T, B> where
    B: Unpin,
    T: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.