pub struct Array<I: Index, T> { /* private fields */ }Expand description
A dense array of Ts indexed by I.
Implementations§
Source§impl<I: Index, T> Array<I, T>
impl<I: Index, T> Array<I, T>
Sourcepub fn new(size: impl Isomorphic<I::Size>, items: impl Into<Box<[T]>>) -> Self
pub fn new(size: impl Isomorphic<I::Size>, items: impl Into<Box<[T]>>) -> Self
Constructs an Array of size size given its elements.
use multidimension::{Index, Array};
let a: Array<(usize, bool), f32> = Array::new(3, [0.0, 1.0, -1.0, 2.0, 3.0, -2.0]);
assert_eq!(a[(0, false)], 0.0);
assert_eq!(a[(0, true)], 1.0);
assert_eq!(a[(1, false)], -1.0);
assert_eq!(a[(1, true)], 2.0);
assert_eq!(a[(2, false)], 3.0);
assert_eq!(a[(2, true)], -2.0);Sourcepub fn from_fn(size: impl Isomorphic<I::Size>, f: impl FnMut(I) -> T) -> Self
pub fn from_fn(size: impl Isomorphic<I::Size>, f: impl FnMut(I) -> T) -> Self
Construct an Array of size size from a function.
Consider also fn_view().
use multidimension::{Index, Array};
let a: Array<usize, _> = Array::from_fn(10, |x| x % 3 == 0);
assert_eq!(a.as_ref(), [true, false, false, true, false, false, true, false, false, true]);Trait Implementations§
Source§impl<I: Index, T: Clone> View for Array<I, T>
impl<I: Index, T: Clone> View for Array<I, T>
Source§fn diagonal(self, zero: Self::T) -> Diagonal<Self>
fn diagonal(self, zero: Self::T) -> Diagonal<Self>
Returns a
View that maps (i, i) to t when Self maps i to t.
It maps (i, j) to zero if i != j. Read moreSource§fn concat<V: View<T = Self::T>, I: Index, J: Index>(
self,
other: V,
) -> Concat<Self, V, I, J>where
Self::I: Isomorphic<(I, usize, J)>,
<Self::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>,
V::I: Isomorphic<(I, usize, J)>,
<V::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>,
fn concat<V: View<T = Self::T>, I: Index, J: Index>(
self,
other: V,
) -> Concat<Self, V, I, J>where
Self::I: Isomorphic<(I, usize, J)>,
<Self::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>,
V::I: Isomorphic<(I, usize, J)>,
<V::I as Index>::Size: Isomorphic<(I::Size, usize, J::Size)>,
Source§fn from_usize<I: Index, X: Index, J: Index>(
self,
from_length: impl FnOnce(usize) -> X::Size,
) -> FromUsize<Self, I, X, J>where
Self::I: Isomorphic<(I, usize, J)>,
<Self::I as Index>::Size: Isomorphic<<(I, usize, J) as Index>::Size>,
fn from_usize<I: Index, X: Index, J: Index>(
self,
from_length: impl FnOnce(usize) -> X::Size,
) -> FromUsize<Self, I, X, J>where
Self::I: Isomorphic<(I, usize, J)>,
<Self::I as Index>::Size: Isomorphic<<(I, usize, J) as Index>::Size>,
Source§fn to_usize<I: Index, X: Index, J: Index>(self) -> ToUsize<Self, I, X, J>where
Self::I: Isomorphic<(I, X, J)>,
<Self::I as Index>::Size: Isomorphic<<(I, X, J) as Index>::Size>,
fn to_usize<I: Index, X: Index, J: Index>(self) -> ToUsize<Self, I, X, J>where
Self::I: Isomorphic<(I, X, J)>,
<Self::I as Index>::Size: Isomorphic<<(I, X, J) as Index>::Size>,
Source§fn insert_one<I: Index, J: Index, K: Index>(
self,
size: J::Size,
) -> InsertOne<Self, I, J, K>
fn insert_one<I: Index, J: Index, K: Index>( self, size: J::Size, ) -> InsertOne<Self, I, J, K>
Source§fn remove_one<I: Index, J: Index, K: Index>(self) -> RemoveOne<Self, I, J, K>where
Self::I: Isomorphic<(I, J, K)>,
<Self::I as Index>::Size: Isomorphic<(I::Size, J::Size, K::Size)>,
fn remove_one<I: Index, J: Index, K: Index>(self) -> RemoveOne<Self, I, J, K>where
Self::I: Isomorphic<(I, J, K)>,
<Self::I as Index>::Size: Isomorphic<(I::Size, J::Size, K::Size)>,
Source§fn binary<V: View, B>(self, other: V) -> Zip<Self, V, B>
fn binary<V: View, B>(self, other: V) -> Zip<Self, V, B>
Creates a
View that pairs of an element of self and an element of
other, then applies binary operator B. Read moreSource§fn iso<J>(self) -> Iso<Self, J>
fn iso<J>(self) -> Iso<Self, J>
Change the index type of this
View to an Isomorphic type.Source§fn rows<I: Index, J: Index>(&self) -> Rows<&Self, I, J>
fn rows<I: Index, J: Index>(&self) -> Rows<&Self, I, J>
Returns a
View whose at(i) returns self.row(i).Auto Trait Implementations§
impl<I, T> Freeze for Array<I, T>
impl<I, T> RefUnwindSafe for Array<I, T>
impl<I, T> Send for Array<I, T>
impl<I, T> Sync for Array<I, T>
impl<I, T> Unpin for Array<I, T>
impl<I, T> UnwindSafe for Array<I, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more