pub struct FlatJagged<V, I, T>{ /* private fields */ }
Expand description
A variable cardinality, jagged, D2
vector represented by a tuple of a
flat D1
storage and row end indices.
Flattening jagged vectors might be useful in improving cache locality.
§Examples
use orx_v::*;
let row_end_indices = [1, 3, 3, 6];
let storage = [0, 1, 2, 3, 4, 5];
let jagged = storage.as_jagged(&row_end_indices);
assert_eq!(jagged.card([]), 4);
assert_eq!(jagged.card([0]), 1);
assert_eq!(jagged.card([1]), 2);
assert_eq!(jagged.card([2]), 0);
assert_eq!(jagged.card([3]), 3);
assert_eq!(
jagged.equality(&vec![vec![0], vec![1, 2], vec![], vec![3, 4, 5]]),
Equality::Equal,
);
Note that row end indices can be any V1<usize>
.
Alternatively, it might be created internally from row lengths.
use orx_v::*;
let row_lengths = [1, 2, 0, 3];
let storage = [0, 1, 2, 3, 4, 5];
let jagged = storage.as_jagged_from_row_lengths(&row_lengths);
assert_eq!(jagged.card([]), 4);
assert_eq!(jagged.card([0]), 1);
assert_eq!(jagged.card([1]), 2);
assert_eq!(jagged.card([2]), 0);
assert_eq!(jagged.card([3]), 3);
assert_eq!(
jagged.equality(&vec![vec![0], vec![1, 2], vec![], vec![3, 4, 5]]),
Equality::Equal,
);
Implementations§
Source§impl<V, I, T> FlatJagged<V, I, T>
impl<V, I, T> FlatJagged<V, I, T>
Sourcepub fn into_inner(self) -> (V, I)
pub fn into_inner(self) -> (V, I)
Transforms the flat-jagged vec into two of its underlying V1
s:
flat_vec
which is the flattened storage of the jagged vec, androw_end_indices
which is the scan of row lengths.
§Examples
use orx_v::*;
let row_lengths = [0, 3, 2, 1];
let storage = [0, 1, 2, 3, 4, 5];
let jagged = storage.as_jagged_from_row_lengths(&row_lengths);
assert_eq!(jagged.card([]), 4);
assert_eq!(jagged.card([0]), 0);
assert_eq!(jagged.card([1]), 3);
assert_eq!(jagged.card([2]), 2);
assert_eq!(jagged.card([3]), 1);
assert_eq!(
jagged.equality(&vec![vec![], vec![0, 1, 2], vec![3, 4], vec![5]]),
Equality::Equal,
);
let (v1, end_indices) = jagged.into_inner();
assert_eq!(
v1.equality(&[0, 1, 2, 3, 4, 5]),
Equality::Equal
);
assert_eq!(
end_indices.equality(&[0, 3, 5, 6]),
Equality::Equal
);
Trait Implementations§
Source§impl<V, I, T> Debug for FlatJagged<V, I, T>
impl<V, I, T> Debug for FlatJagged<V, I, T>
Source§impl<V, I, T> NVec<D2, T> for FlatJagged<V, I, T>
impl<V, I, T> NVec<D2, T> for FlatJagged<V, I, T>
Source§fn at(&self, idx: impl IntoIdx<D2>) -> T
fn at(&self, idx: impl IntoIdx<D2>) -> T
Returns the element at the
idx
-th position of the vector. Read moreSource§fn child(&self, i: <D2 as Dim>::ChildIdx) -> impl NVec<<D2 as Dim>::PrevDim, T>
fn child(&self, i: <D2 as Dim>::ChildIdx) -> impl NVec<<D2 as Dim>::PrevDim, T>
Returns the
i
-th child of the vector. Read moreSource§fn all(&self) -> impl Iterator<Item = T>
fn all(&self) -> impl Iterator<Item = T>
Returns a flattened iterator over all scalar (D0) elements of the vector. Read more
Source§fn num_children(&self) -> usize
fn num_children(&self) -> usize
Returns the number of children of the vector; i.e., number of
elements of the one lower dimension. Read more
Source§fn card(&self, idx: impl Into<D::CardIdx>) -> usize
fn card(&self, idx: impl Into<D::CardIdx>) -> usize
Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§fn is_bounded(&self) -> bool
fn is_bounded(&self) -> bool
Returns whether or not the vector is bounded. Read more
Source§fn is_rectangular(&self) -> bool
fn is_rectangular(&self) -> bool
Returns whether or not the cardinalities of the vector are rectangular.
A rectangular vector of dimension
D
has the same number of children
at a given lower dimension for all indices. Read moreSource§fn is_unbounded(&self) -> bool
fn is_unbounded(&self) -> bool
Returns whether or not the vector is unbounded. Read more
Source§fn in_bounds(&self, idx: impl Into<D::LeqIdx>) -> bool
fn in_bounds(&self, idx: impl Into<D::LeqIdx>) -> bool
Returns whether or not the given
idx
is in bounds. Read moreSource§fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>
fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>
Returns the cardinality equality of this vec with the
other
: Read moreSource§fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>
fn try_at(&self, idx: impl IntoIdx<D>) -> Option<T>
Returns the element at the
idx
-th position of the vector if the
index is in_bounds
; returns None otherwise. Read moreSource§fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>where
T: PartialEq,
fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>where
T: PartialEq,
Returns the equality of this vec with the
other
: Read moreSource§impl<V, I, T> NVecMut<D2, T> for FlatJagged<V, I, T>
impl<V, I, T> NVecMut<D2, T> for FlatJagged<V, I, T>
Source§fn at_mut<Idx: IntoIdx<D2>>(&mut self, idx: Idx) -> &mut T
fn at_mut<Idx: IntoIdx<D2>>(&mut self, idx: Idx) -> &mut T
Returns a mutable reference to the element at the
idx
-th
position of the vector. Read moreSource§fn child_mut(
&mut self,
i: <D2 as Dim>::ChildIdx,
) -> impl NVecMut<<D2 as Dim>::PrevDim, T>
fn child_mut( &mut self, i: <D2 as Dim>::ChildIdx, ) -> impl NVecMut<<D2 as Dim>::PrevDim, T>
Returns a mutable reference to the
i
-th child of the vector. Read moreSource§fn mut_all<F>(&mut self, f: F)
fn mut_all<F>(&mut self, f: F)
Applies the mutating function
f
over all scalar elements of the vector. Read moreAuto Trait Implementations§
impl<V, I, T> Freeze for FlatJagged<V, I, T>
impl<V, I, T> RefUnwindSafe for FlatJagged<V, I, T>
impl<V, I, T> Send for FlatJagged<V, I, T>
impl<V, I, T> Sync for FlatJagged<V, I, T>
impl<V, I, T> Unpin for FlatJagged<V, I, T>
impl<V, I, T> UnwindSafe for FlatJagged<V, 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
Source§impl<T, V> V2AsMatrix<T> for V
impl<T, V> V2AsMatrix<T> for V
Source§fn into_matrix(self) -> V2MatrixRowMajor<T, Self>
fn into_matrix(self) -> V2MatrixRowMajor<T, Self>
Converts the rectangular
D2
vector into a row-major matrix. Read moreSource§fn as_matrix(&self) -> V2MatrixRowMajor<T, &Self>
fn as_matrix(&self) -> V2MatrixRowMajor<T, &Self>
Creates a row-major matrix view over the rectangular
D2
vector. Read moreSource§fn as_matrix_mut(&mut self) -> V2MatrixRowMajor<T, &mut Self>
fn as_matrix_mut(&mut self) -> V2MatrixRowMajor<T, &mut Self>
Creates a mutable row-major matrix view over the rectangular
D2
vector. Read moreSource§fn into_matrix_col_major(self) -> V2MatrixColMajor<T, Self>
fn into_matrix_col_major(self) -> V2MatrixColMajor<T, Self>
Converts the rectangular
D2
vector into a column-major matrix. Read moreSource§fn as_matrix_col_major(&self) -> V2MatrixColMajor<T, &Self>
fn as_matrix_col_major(&self) -> V2MatrixColMajor<T, &Self>
Creates a column-major matrix view over the rectangular
D2
vector. Read moreSource§fn as_matrix_col_major_mut(&mut self) -> V2MatrixColMajor<T, &mut Self>
fn as_matrix_col_major_mut(&mut self) -> V2MatrixColMajor<T, &mut Self>
Creates a mutable column-major matrix view over the rectangular
D2
vector. Read more