orx_v

Struct FlatJagged

Source
pub struct FlatJagged<V, I, T>
where V: NVec<D1, T>, I: NVec<D1, usize>,
{ /* 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>
where V: NVec<D1, T>, I: NVec<D1, usize>,

Source

pub fn into_inner(self) -> (V, I)

Transforms the flat-jagged vec into two of its underlying V1s:

  • flat_vec which is the flattened storage of the jagged vec, and
  • row_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>
where T: Debug, V: NVec<D1, T>, I: NVec<D1, usize>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V, I, T> NVec<D2, T> for FlatJagged<V, I, T>
where V: NVec<D1, T>, I: NVec<D1, usize>,

Source§

fn at(&self, idx: impl IntoIdx<D2>) -> T

Returns the element at the idx-th position of the vector. Read more
Source§

fn child(&self, i: <D2 as Dim>::ChildIdx) -> impl NVec<<D2 as Dim>::PrevDim, T>

Returns the i-th child of the vector. Read more
Source§

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

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

Returns the cardinality of the vec in any of the lower dimensions. Read more
Source§

fn is_bounded(&self) -> bool

Returns whether or not the vector is bounded. Read more
Source§

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 more
Source§

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

Returns whether or not the given idx is in bounds. Read more
Source§

fn card_equality(&self, other: &impl NVec<D, T>) -> CardEquality<D>

Returns the cardinality equality of this vec with the other: Read more
Source§

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 more
Source§

fn equality(&self, other: &impl NVec<D, T>) -> Equality<D>
where T: PartialEq,

Returns the equality of this vec with the other: Read more
Source§

fn children(&self) -> impl Iterator<Item = impl NVec<D::PrevDim, T>>

Returns an iterator of all children of the vector. Read more
Source§

fn all_in( &self, indices: impl Iterator<Item = impl IntoIdx<D>>, ) -> impl Iterator<Item = T>

Returns an iterator of elements for the given indices. Read more
Source§

impl<V, I, T> NVecMut<D2, T> for FlatJagged<V, I, T>
where V: NVec<D1, T> + NVecMut<D1, T>, I: NVec<D1, usize>,

Source§

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 more
Source§

fn set<Idx: IntoIdx<D2>>(&mut self, idx: Idx, value: T)

Sets valueof the element at the idx-th position of the vector. Read more
Source§

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 more
Source§

fn mut_all<F>(&mut self, f: F)
where F: FnMut(&mut T),

Applies the mutating function f over all scalar elements of the vector. Read more
Source§

fn reset_all(&mut self, value: T)
where T: PartialEq + Copy,

Sets all elements of the vector to the given value. This method is often used at initialization stage of algorithms. Read more
Source§

fn try_at_mut(&mut self, idx: impl IntoIdx<D>) -> Option<&mut T>

Returns a mutable reference to the element at the idx-th position of the vector if the index is in_bounds; returns None otherwise. Read more

Auto Trait Implementations§

§

impl<V, I, T> Freeze for FlatJagged<V, I, T>
where V: Freeze, I: Freeze,

§

impl<V, I, T> RefUnwindSafe for FlatJagged<V, I, T>

§

impl<V, I, T> Send for FlatJagged<V, I, T>
where V: Send, I: Send, T: Send,

§

impl<V, I, T> Sync for FlatJagged<V, I, T>
where V: Sync, I: Sync, T: Sync,

§

impl<V, I, T> Unpin for FlatJagged<V, I, T>
where V: Unpin, I: Unpin, T: Unpin,

§

impl<V, I, T> UnwindSafe for FlatJagged<V, I, T>
where V: UnwindSafe, I: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, V> V2AsMatrix<T> for V
where V: NVec<D2, T>,

Source§

fn into_matrix(self) -> V2MatrixRowMajor<T, Self>
where Self: NVec<D2, T>,

Converts the rectangular D2 vector into a row-major matrix. Read more
Source§

fn as_matrix(&self) -> V2MatrixRowMajor<T, &Self>
where Self: NVec<D2, T>,

Creates a row-major matrix view over the rectangular D2 vector. Read more
Source§

fn as_matrix_mut(&mut self) -> V2MatrixRowMajor<T, &mut Self>
where Self: NVecMut<D2, T>,

Creates a mutable row-major matrix view over the rectangular D2 vector. Read more
Source§

fn into_matrix_col_major(self) -> V2MatrixColMajor<T, Self>
where Self: NVec<D2, T>,

Converts the rectangular D2 vector into a column-major matrix. Read more
Source§

fn as_matrix_col_major(&self) -> V2MatrixColMajor<T, &Self>
where Self: NVec<D2, T>,

Creates a column-major matrix view over the rectangular D2 vector. Read more
Source§

fn as_matrix_col_major_mut(&mut self) -> V2MatrixColMajor<T, &mut Self>
where Self: NVecMut<D2, T>,

Creates a mutable column-major matrix view over the rectangular D2 vector. Read more
Source§

impl<D, V, T> NVecCore<D, T> for V
where D: Dim, V: NVecCoreSealed<D, T>,

Source§

impl<T, N> V2<T> for N
where N: NVec<D2, T>,

Source§

impl<T, N> V2Mut<T> for N
where N: NVecMut<D2, T>,