orx_v

Struct NewV4

Source
pub struct NewV4;
Expand description

V4<T> (NVec<D4, T>) builder.

Implementations§

Source§

impl NewV4

Source

pub fn constant<T: Copy>( self, value: T, ) -> ConstantVec<D4, T, UnboundedCard<D4>>

Creates a constant vector of dimension D4 which returns the same value for any input index.

Since a constant vector assumes all positions of the vector is filled with value, the vector on construction has UnboundedCard; i.e., it has a value for any possible index.

In order to convert the constant vector into one with a provided bound, you may use the with_rectangular_bounds and with_variable_bounds methods.

See V.d2().constant for examples.

Source

pub fn empty<T>(self) -> EmptyVec<D4, T>

Creates an empty vector of dimension D4.

§Examples
use orx_v::*;

let v4 = V.d4().empty::<i32>();

assert_eq!(v4.card([]), 0);
assert_eq!(v4.in_bounds([0, 0, 0, 0]), false);
assert_eq!(v4.try_at([0, 0, 0, 0]), None);
assert_eq!(v4.all().next(), None);
Source

pub fn sparse<T: Copy>( self, default_value: T, ) -> SparseVec<D4, T, UnboundedCard<D4>, DefaultLookup<D4, T>>

Creates a sparse vector of dimension D4 with an initially empty lookup.

Sparse vectors maintain a (idx, value) lookup under the hood and has a default_value, and works as follows:

  • at(idx) returns the corresponding value if the idx exists in the lookup, or the default value otherwise.
  • at_mut(idx) first adds (idx, default_value) to the lookup only if it is absent, and returns a mutable reference to the value in the lookup.

The objective of sparse vectors are to significantly reduce the memory requirement of vectors which has the same value for most of its positions. Consider for instance a 100x100 matrix which is all zeros except for the element at the (42,42)-th position which is 42. This matrix can be represented by a sparse vector with lookup containing only one element.

Since sparse vector assumes all indices absent in the lookup have the default_value, the vector on construction has UnboundedCard; i.e., it has a value for any possible index.

In order to convert the sparse vector into one with a provided bound, you may use the with_rectangular_bounds and with_variable_bounds methods.

See V.d2().sparse for examples.

Source

pub fn sparse_from<T: Copy, L: Lookup<<D4 as Dim>::Idx, T>>( self, lookup: L, default_value: T, ) -> SparseVec<D4, T, UnboundedCard<D4>, L>

Creates a sparse vector of dimension D4 with the provided lookup.

Sparse vectors maintain a (idx, value) lookup under the hood and has a default_value, and works as follows:

  • at(idx) returns the corresponding value if the idx exists in the lookup, or the default value otherwise.
  • at_mut(idx) first adds (idx, default_value) to the lookup only if it is absent, and returns a mutable reference to the value in the lookup.

There might be alternative choices of the lookup type. It is required that the collection implements the Lookup trait. The std collection HashMap and no-std collection BTreeMap already implement this trait and can be readily be usd in sparse vectors.

The objective of sparse vectors are to significantly reduce the memory requirement of vectors which has the same value for most of its positions. Consider for instance a 100x100 matrix which is all zeros except for the element at the (42,42)-th position which is 42. This matrix can be represented by a sparse vector with lookup containing only one element.

Since sparse vector assumes all indices absent in the lookup have the default_value, the vector on construction has UnboundedCard; i.e., it has a value for any possible index.

In order to convert the sparse vector into one with a provided bound, you may use the with_rectangular_bounds and with_variable_bounds methods.

See V.d2().sparse_from for examples.

Source

pub fn fun<T, F>(self, at: F) -> FunVec<D4, T, F, UnboundedCard<D4>>
where F: Fn(<D4 as Dim>::Idx) -> T,

Creates a functional vector of dimension D4.

Since the functional vector is capable of creating an element for any given index, the vector on construction has UnboundedCard; i.e., it has a value for any possible index.

In order to convert the sparse vector into one with a provided bound, you may use the with_rectangular_bounds and with_variable_bounds methods.

See V.d2().fun for examples.

Auto Trait Implementations§

§

impl Freeze for NewV4

§

impl RefUnwindSafe for NewV4

§

impl Send for NewV4

§

impl Sync for NewV4

§

impl Unpin for NewV4

§

impl UnwindSafe for NewV4

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.