orx_v

Trait IntoJagged

Source
pub trait IntoJagged<T>: Sized + NVec<D1, T> {
    // Provided methods
    fn into_jagged<I>(self, row_end_indices: I) -> FlatJagged<Self, I, T>
       where I: NVec<D1, usize> { ... }
    fn as_jagged<I>(&self, row_end_indices: I) -> FlatJagged<&Self, I, T>
       where I: NVec<D1, usize> { ... }
    fn as_jagged_mut<I>(
        &mut self,
        row_end_indices: I,
    ) -> FlatJagged<&mut Self, I, T>
       where I: NVec<D1, usize> { ... }
    fn into_jagged_from_row_lengths<I>(
        self,
        row_lengths: &I,
    ) -> FlatJagged<Self, Vec<usize>, T>
       where I: NVec<D1, usize> { ... }
    fn as_jagged_from_row_lengths<I>(
        &self,
        row_lengths: &I,
    ) -> FlatJagged<&Self, Vec<usize>, T>
       where I: NVec<D1, usize> { ... }
    fn as_jagged_mut_from_row_lengths<I>(
        &mut self,
        row_lengths: &I,
    ) -> FlatJagged<&mut Self, Vec<usize>, T>
       where I: NVec<D1, usize> { ... }
    fn into_jagged_with_uniform_lengths(
        self,
        uniform_length: usize,
    ) -> FlatJagged<Self, UniformEndIndices, T> { ... }
    fn as_jagged_with_uniform_lengths(
        &self,
        uniform_length: usize,
    ) -> FlatJagged<&Self, UniformEndIndices, T> { ... }
    fn as_jagged_mut_with_uniform_lengths(
        &mut self,
        uniform_length: usize,
    ) -> FlatJagged<&mut Self, UniformEndIndices, T> { ... }
}
Expand description

Transforms a D1 vector into a jagged D2 vector via into_x methods; or alternatively, creates a jagged D2 vector view as_x methods.

Provided Methods§

Source

fn into_jagged<I>(self, row_end_indices: I) -> FlatJagged<Self, I, T>
where I: NVec<D1, usize>,

Converts a D1 vector into a jagged D2 vector where each row is identified by row_end_indices.

Notice that row_end_indices is any V1<usize> which might be a vector of indices or a functional vector, etc.

§Panics

Panics if:

  • row_end_indices is not non-decreasing, or
  • last element of row_end_indices is not equal to the length of this flat vector.
§Examples
use orx_v::*;

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let end_indices = vec![1, 1, 4, 10]; // lengths => [1, 0, 3, 6]
let v2 = v1.into_jagged(end_indices);
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]]),
    Equality::Equal
);

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let end_indices = V.d1().fun(|[i]| (i + 1) * 5).bounded(2); // lengths => [5, 5]
let v2 = v1.into_jagged(end_indices);
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 3, 4], vec![5, 6, 7, 8, 9]]),
    Equality::Equal
);
Source

fn as_jagged<I>(&self, row_end_indices: I) -> FlatJagged<&Self, I, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a jagged D2 vector view where each row is identified by row_end_indices.

Notice that row_end_indices is any V1<usize> which might be a vector of indices or a functional vector, etc.

§Panics

Panics if:

  • row_end_indices is not non-decreasing, or
  • last element of row_end_indices is not equal to the length of this flat vector.
§Examples
use orx_v::*;

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

let end_indices = vec![1, 1, 4, 10]; // lengths => [1, 0, 3, 6]
let v2 = v1.as_jagged(&end_indices);
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]]),
    Equality::Equal
);

let end_indices = V.d1().fun(|[i]| (i + 1) * 5).bounded(2); // lengths => [5, 5]
let v2 = v1.as_jagged(&end_indices);
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 3, 4], vec![5, 6, 7, 8, 9]]),
    Equality::Equal
);
Source

fn as_jagged_mut<I>( &mut self, row_end_indices: I, ) -> FlatJagged<&mut Self, I, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a mutable jagged D2 vector view where each row is identified by row_end_indices.

Notice that row_end_indices is any V1<usize> which might be a vector of indices or a functional vector, etc.

§Panics

Panics if:

  • row_end_indices is not non-decreasing, or
  • last element of row_end_indices is not equal to the length of this flat vector.
§Examples
use orx_v::*;

let mut v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

let end_indices = vec![1, 1, 4, 10]; // lengths => [1, 0, 3, 6]
let mut v2 = v1.as_jagged_mut(&end_indices);
*v2.at_mut([2, 2]) += 10;
*v2.at_mut([3, 4]) *= 10;
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 13], vec![4, 5, 6, 7, 80, 9]]),
    Equality::Equal
);

let end_indices = V.d1().fun(|[i]| (i + 1) * 5).bounded(2); // lengths => [5, 5]
let mut v2 = v1.as_jagged_mut(&end_indices);
*v2.at_mut([0, 4]) += 100;
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 13, 104], vec![5, 6, 7, 80, 9]]),
    Equality::Equal
);
Source

fn into_jagged_from_row_lengths<I>( self, row_lengths: &I, ) -> FlatJagged<Self, Vec<usize>, T>
where I: NVec<D1, usize>,

Converts a D1 vector into a jagged D2 vector where each row is identified by row_lengths.

Notice that row_lengths is any V1<usize> which might be a vector of indices or a functional vector, etc.

Internally, this method will evaluate row_end_indices, store it in a Vec<usize> and call into_jagged method.

§Panics

Panics if the sum of row_lengths do not add up to the length of this vector; i.e., self.card([]).

§Examples
use orx_v::*;

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let row_lengths = vec![1, 0, 3, 6];
let v2 = v1.into_jagged_from_row_lengths(&row_lengths);
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]]),
    Equality::Equal
);

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let row_lengths = V.d1().constant(5).bounded(2); // lengths => [5, 5]
let v2 = v1.into_jagged_from_row_lengths(&row_lengths);
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 3, 4], vec![5, 6, 7, 8, 9]]),
    Equality::Equal
);
Source

fn as_jagged_from_row_lengths<I>( &self, row_lengths: &I, ) -> FlatJagged<&Self, Vec<usize>, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a jagged D2 vector view where each row is identified by row_lengths.

Notice that row_lengths is any V1<usize> which might be a vector of indices or a functional vector, etc.

Internally, this method will evaluate row_end_indices, store it in a Vec<usize> and call into_jagged method.

§Panics

Panics if the sum of row_lengths do not add up to the length of this vector; i.e., self.card([]).

§Examples
use orx_v::*;

let v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

let row_lengths = vec![1, 0, 3, 6]; // lengths => [1, 0, 3, 6]
let v2 = v1.as_jagged_from_row_lengths(&row_lengths);
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]]),
    Equality::Equal
);

let row_lengths = V.d1().constant(5).bounded(2); // lengths => [5, 5]
let v2 = v1.as_jagged_from_row_lengths(&row_lengths);
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 3, 4], vec![5, 6, 7, 8, 9]]),
    Equality::Equal
);
Source

fn as_jagged_mut_from_row_lengths<I>( &mut self, row_lengths: &I, ) -> FlatJagged<&mut Self, Vec<usize>, T>
where I: NVec<D1, usize>,

From a flat D1 vector, creates a mutable jagged D2 vector view where each row is identified by row_lengths.

Notice that row_lengths is any V1<usize> which might be a vector of indices or a functional vector, etc.

Internally, this method will evaluate row_end_indices, store it in a Vec<usize> and call into_jagged method.

§Panics

Panics if the sum of row_lengths do not add up to the length of this vector; i.e., self.card([]).

§Examples
use orx_v::*;

let mut v1 = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

let row_lengths = vec![1, 0, 3, 6]; // lengths => [1, 0, 3, 6]
let mut v2 = v1.as_jagged_mut_from_row_lengths(&row_lengths);
*v2.at_mut([2, 2]) += 10;
*v2.at_mut([3, 4]) *= 10;
assert_eq!(
    v2.equality(&[vec![0], vec![], vec![1, 2, 13], vec![4, 5, 6, 7, 80, 9]]),
    Equality::Equal
);

let row_lengths = V.d1().constant(5).bounded(2); // lengths => [5, 5]
let mut v2 = v1.as_jagged_mut_from_row_lengths(&row_lengths);
*v2.at_mut([0, 4]) += 100;
assert_eq!(
    v2.equality(&[vec![0, 1, 2, 13, 104], vec![5, 6, 7, 80, 9]]),
    Equality::Equal
);
Source

fn into_jagged_with_uniform_lengths( self, uniform_length: usize, ) -> FlatJagged<Self, UniformEndIndices, T>

Converts a D1 vector into a jagged D2 vector where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length.

§Examples
use orx_v::*;

let v1 = [1, 2, 3, 4, 5, 6, 7, 8];

let v2 = v1.into_jagged_with_uniform_lengths(3);

assert_eq!(v2.card([]), 3);
assert_eq!(v2.card([0]), 3);
assert_eq!(v2.at([1, 2]), 6);

assert_eq!(
    v2.equality(&[vec![1, 2, 3], vec![4, 5, 6], vec![7, 8]]),
    Equality::Equal
);
Source

fn as_jagged_with_uniform_lengths( &self, uniform_length: usize, ) -> FlatJagged<&Self, UniformEndIndices, T>

From a flat D1 vector, creates a jagged D2 vector view where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length.

§Examples
use orx_v::*;

let v1 = [1, 2, 3, 4, 5, 6, 7, 8];

let v2 = v1.as_jagged_with_uniform_lengths(3);

assert_eq!(v2.card([]), 3);
assert_eq!(v2.card([0]), 3);
assert_eq!(v2.at([1, 2]), 6);

assert_eq!(
    v2.equality(&[vec![1, 2, 3], vec![4, 5, 6], vec![7, 8]]),
    Equality::Equal
);
Source

fn as_jagged_mut_with_uniform_lengths( &mut self, uniform_length: usize, ) -> FlatJagged<&mut Self, UniformEndIndices, T>

From a flat D1 vector, creates a mutable jagged D2 vector view where each row has the given uniform_length, except that the last row might have fewer elements if the cardinality of the D1 vector is not divisible by the uniform length.

§Examples
use orx_v::*;

let mut v1 = [1, 2, 3, 4, 5, 6, 7, 8];

let mut v2 = v1.as_jagged_mut_with_uniform_lengths(3);

v2.set([1, 2], 66);
*v2.at_mut([2, 0]) = 77;

assert_eq!(
    v2.equality(&[vec![1, 2, 3], vec![4, 5, 66], vec![77, 8]]),
    Equality::Equal
);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, V: Sized + NVec<D1, T>> IntoJagged<T> for V