pub struct CircularArray<const N: usize, A, T> { /* private fields */ }Expand description
A circular array of N dimensions for elements of type T.
Supports any fixed size contiguous element buffer implementing AsRef<[T]>
and AsMut<T>.
Implementations§
Source§impl<const N: usize, A, T> CircularArray<N, A, T>
impl<const N: usize, A, T> CircularArray<N, A, T>
Sourcepub fn new(shape: [usize; N], array: A) -> CircularArray<N, A, T>
pub fn new(shape: [usize; N], array: A) -> CircularArray<N, A, T>
Create a new CircularArray from the given buffer.
§Examples
let shape = [3, 3, 3];
let array = Vec::from_iter(0..shape.iter().product());
let circular_array = CircularArray::new(shape, array);Sourcepub fn new_offset(
shape: [usize; N],
offset: [usize; N],
array: A,
) -> CircularArray<N, A, T>
pub fn new_offset( shape: [usize; N], offset: [usize; N], array: A, ) -> CircularArray<N, A, T>
Create a new CircularArray from the given buffer and offset.
§Examples
let shape = [3, 3, 3];
let array = Vec::from_iter(0..shape.iter().product());
// Offset by 1 on axis 0.
let circular_array = CircularArray::new_offset(shape, [1, 0, 0], array);Sourcepub fn offset(&self) -> &[usize; N]
pub fn offset(&self) -> &[usize; N]
Get the array offset. This is not always incremented sequentually. Where a
mutating operation inserts elements equal to the product of the array shape,
the offset will be set to [0; N].
Sourcepub fn slice_len(&self, axis: usize) -> usize
pub fn slice_len(&self, axis: usize) -> usize
Get the number of elements for a single slice of the buffer, for the given
axis. Pushing n slices of elements onto an axis requires n * slice_len
elements to be passed to the respective method.
Sourcepub fn next_offset(&self, axis: usize, n: isize) -> usize
pub fn next_offset(&self, axis: usize, n: isize) -> usize
Get the offset value after adding n slices to the given axis.
Source§impl<const N: usize, T> CircularArray<N, Vec<T>, T>
impl<const N: usize, T> CircularArray<N, Vec<T>, T>
Sourcepub fn from_iter(shape: [usize; N], iter: impl Iterator<Item = T>) -> Self
pub fn from_iter(shape: [usize; N], iter: impl Iterator<Item = T>) -> Self
Create a new CircularArrayVec from an iterator.
§Examples
let shape = [3, 3, 3];
let circular_array = CircularArrayVec::from_iter(shape, 0..shape.iter().product());Sourcepub fn from_iter_offset(
shape: [usize; N],
offset: [usize; N],
iter: impl Iterator<Item = T>,
) -> Self
pub fn from_iter_offset( shape: [usize; N], offset: [usize; N], iter: impl Iterator<Item = T>, ) -> Self
Create a new CircularArrayVec from an iterator with the given offset.
§Examples
let shape = [3, 3, 3];
// Offset by 1 on axis 0.
let circular_array = CircularArrayVec::from_iter_offset(shape, [1, 0, 0], 0..shape.iter().product());Source§impl<const N: usize, T> CircularArray<N, Box<[T]>, T>
impl<const N: usize, T> CircularArray<N, Box<[T]>, T>
Sourcepub fn from_iter(shape: [usize; N], iter: impl Iterator<Item = T>) -> Self
pub fn from_iter(shape: [usize; N], iter: impl Iterator<Item = T>) -> Self
Create a new CircularArrayBox from an iterator.
§Examples
let shape = [3, 3, 3];
let circular_array = CircularArrayBox::from_iter(shape, 0..shape.iter().product());Sourcepub fn from_iter_offset(
shape: [usize; N],
iter: impl Iterator<Item = T>,
offset: [usize; N],
) -> Self
pub fn from_iter_offset( shape: [usize; N], iter: impl Iterator<Item = T>, offset: [usize; N], ) -> Self
Create a new CircularArrayBox from an iterator with the given offset.
§Examples
let shape = [3, 3, 3];
// Offset by 1 on axis 0.
let circular_array = CircularArrayBox::from_iter_offset(shape, 0..shape.iter().product(), [1, 0, 0]);Trait Implementations§
Source§impl<'a, const N: usize, A: AsRef<[T]>, T: 'a> CircularIndex<'a, N, T> for CircularArray<N, A, T>
impl<'a, const N: usize, A: AsRef<[T]>, T: 'a> CircularIndex<'a, N, T> for CircularArray<N, A, T>
Source§fn iter(&'a self) -> impl ExactSizeIterator<Item = &'a T>
fn iter(&'a self) -> impl ExactSizeIterator<Item = &'a T>
Source§fn iter_raw(&'a self) -> impl ExactSizeIterator<Item = &'a T>
fn iter_raw(&'a self) -> impl ExactSizeIterator<Item = &'a T>
Source§fn iter_index(
&'a self,
axis: usize,
index: usize,
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_index( &'a self, axis: usize, index: usize, ) -> impl ExactSizeIterator<Item = &'a T>
Source§fn iter_index_raw(
&'a self,
axis: usize,
index: usize,
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_index_raw( &'a self, axis: usize, index: usize, ) -> impl ExactSizeIterator<Item = &'a T>
Source§fn iter_range(
&'a self,
axis: usize,
range: Range<usize>,
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_range( &'a self, axis: usize, range: Range<usize>, ) -> impl ExactSizeIterator<Item = &'a T>
range for the given axis,
aligned to the offset.
This is equivalent to CircularIndex::iter_slice where all axis
ranges are exhaustive except for the specified axis. Read moreSource§fn iter_range_raw(
&'a self,
axis: usize,
range: Range<usize>,
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_range_raw( &'a self, axis: usize, range: Range<usize>, ) -> impl ExactSizeIterator<Item = &'a T>
range for the given axis.
This is equivalent to CircularIndex::iter_slice_raw where all axis
ranges are exhaustive except for the specified axis. Read moreSource§fn iter_slice(
&'a self,
slice: [Range<usize>; N],
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_slice( &'a self, slice: [Range<usize>; N], ) -> impl ExactSizeIterator<Item = &'a T>
slice, aligned to the offset. Read moreSource§fn iter_slice_raw(
&'a self,
slice: [Range<usize>; N],
) -> impl ExactSizeIterator<Item = &'a T>
fn iter_slice_raw( &'a self, slice: [Range<usize>; N], ) -> impl ExactSizeIterator<Item = &'a T>
slice. Read moreSource§impl<'a, const N: usize, A: AsRef<[T]> + AsMut<[T]>, T: Clone + 'a> CircularMut<'a, N, T> for CircularArray<N, A, T>
impl<'a, const N: usize, A: AsRef<[T]> + AsMut<[T]>, T: Clone + 'a> CircularMut<'a, N, T> for CircularArray<N, A, T>
Source§fn get_mut(&mut self, index: [usize; N]) -> &mut T
fn get_mut(&mut self, index: [usize; N]) -> &mut T
Source§fn get_mut_raw(&mut self, index: [usize; N]) -> &mut T
fn get_mut_raw(&mut self, index: [usize; N]) -> &mut T
CircularArray::offset. Read moreSource§fn push_front(&'a mut self, axis: usize, el: &'a [T])
fn push_front(&'a mut self, axis: usize, el: &'a [T])
axis, aligned to the offset.
Elements must be an exact multiple of the slice size for the given axis.
See CircularArray::slice_len. Read moreSource§fn push_front_iter<'b, I>(&mut self, axis: usize, el: I)
fn push_front_iter<'b, I>(&mut self, axis: usize, el: I)
axis, aligned to the offset.
Elements must be an exact multiple of the slice size for the given axis.
See CircularArray::slice_len. Read moreSource§fn push_front_raw(&'a mut self, axis: usize, el: &'a [T])
fn push_front_raw(&'a mut self, axis: usize, el: &'a [T])
axis, taking into account only
the offset of the given axis. Elements must be an exact multiple of
the slice size for the given axis. See CircularArray::slice_len. Read moreSource§fn push_front_raw_iter<'b, I>(&mut self, axis: usize, el: I)
fn push_front_raw_iter<'b, I>(&mut self, axis: usize, el: I)
axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len. Read moreSource§fn push_back(&'a mut self, axis: usize, el: &'a [T])
fn push_back(&'a mut self, axis: usize, el: &'a [T])
axis, taking into account the
offsets of all exes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len. Read moreSource§fn push_back_iter<'b, I>(&mut self, axis: usize, el: I)
fn push_back_iter<'b, I>(&mut self, axis: usize, el: I)
axis, taking into account the
offsets of all exes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len. Read moreSource§fn push_back_raw(&'a mut self, axis: usize, el: &'a [T])
fn push_back_raw(&'a mut self, axis: usize, el: &'a [T])
axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len. Read moreSource§fn push_back_raw_iter<'b, I>(&mut self, axis: usize, el: I)
fn push_back_raw_iter<'b, I>(&mut self, axis: usize, el: I)
axis, taking into account the
offsets of all axes. Elements must be an exact multiple of the slice
size for the given axis. See CircularArray::slice_len. Read more