pub struct NewV3;
Expand description
V3<T>
(NVec<D3, T>
) builder.
Implementations§
Source§impl NewV3
impl NewV3
Sourcepub fn constant<T: Copy>(
self,
value: T,
) -> ConstantVec<D3, T, UnboundedCard<D3>>
pub fn constant<T: Copy>( self, value: T, ) -> ConstantVec<D3, T, UnboundedCard<D3>>
Creates a constant vector of dimension D3
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.
Sourcepub fn empty<T>(self) -> EmptyVec<D3, T>
pub fn empty<T>(self) -> EmptyVec<D3, T>
Creates an empty vector of dimension D3
.
§Examples
use orx_v::*;
let v3 = V.d3().empty::<i32>();
assert_eq!(v3.card([]), 0);
assert_eq!(v3.in_bounds([0, 0, 0]), false);
assert_eq!(v3.try_at([0, 0, 0]), None);
assert_eq!(v3.all().next(), None);
Sourcepub fn sparse<T: Copy>(
self,
default_value: T,
) -> SparseVec<D3, T, UnboundedCard<D3>, DefaultLookup<D3, T>>
pub fn sparse<T: Copy>( self, default_value: T, ) -> SparseVec<D3, T, UnboundedCard<D3>, DefaultLookup<D3, T>>
Creates a sparse vector of dimension D3
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.
Sourcepub fn sparse_from<T: Copy, L: Lookup<<D3 as Dim>::Idx, T>>(
self,
lookup: L,
default_value: T,
) -> SparseVec<D3, T, UnboundedCard<D3>, L>
pub fn sparse_from<T: Copy, L: Lookup<<D3 as Dim>::Idx, T>>( self, lookup: L, default_value: T, ) -> SparseVec<D3, T, UnboundedCard<D3>, L>
Creates a sparse vector of dimension D3
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.
Sourcepub fn fun<T, F>(self, at: F) -> FunVec<D3, T, F, UnboundedCard<D3>>
pub fn fun<T, F>(self, at: F) -> FunVec<D3, T, F, UnboundedCard<D3>>
Creates a functional vector of dimension D3
.
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.