Struct IndexedVecXs

Source
pub struct IndexedVecXs<T, const N: usize>
where T: PartialEq + Eq + Hash + Sized + Send,
{ pub values: IndexSet<VecX<T, N>, FxBuildHasher>, pub indices: Vec<usize>, }
Expand description

A structure representing a set of indexed VecX. It is indexed for unique VecX and can efficiently handle sets of VecX in some use cases.

インデックスが付けられたVecXの集合を表す構造体です。 一意のVecXに対してインデックスを持ち、ユースケースによってはVecXの集合を効率的に扱えます。

For example, when considering a set of VecX representing a vertex army in 3D space, this is useful when there are multiple vertices with the same coordinates. This method of data management is often employed in 3D data formats.

例えば、3D空間上の頂点軍を表すVecXの集合を考えた際、同じ座標を持つ頂点が複数存在する場合に有効です。 このデータの管理方法は、しばしば3Dデータのフォーマットに採用されています。

use vec_x::{VecX, IndexedVecXs};

let colors: Vec<VecX<u8, 3>> = [
    [255, 0, 0],
    [0, 255, 0],
    [255, 0, 0],
    [255, 0, 0],
    [0, 0, 255],
    [0, 255, 0],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();
let indexed_colors = IndexedVecXs::from_vec(colors);
let IndexedVecXs { values, indices } = indexed_colors;


// インデックスされた要素の数は元データの一意な要素の数と一致する
assert_eq!(values.len(), 3);
// 元データでの出現順にインデックスが付けられている
assert_eq!(values[0], VecX::new([255, 0, 0]));
assert_eq!(values[1], VecX::new([0, 255, 0]));
assert_eq!(values[2], VecX::new([0, 0, 255]));

// indicesの要素数は元データの要素数と一致する
assert_eq!(indices.len(), 6);
// 同じ要素は同じインデックスを持つ
assert_eq!(indices, vec![0, 1, 0, 0, 2, 1]);

Also, IndexedVecXs implements Index traits, allowing access to elements using indexes.

また、IndexedVecXsIndexトレイトを実装しており、インデックスを使用して要素にアクセスできます。

use vec_x::{VecX, IndexedVecXs};

let colors: Vec<VecX<u8, 3>> = [
   [255, 0, 0],
   [0, 255, 0],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();

let indexed_colors = IndexedVecXs::from_vec(colors);

assert_eq!(indexed_colors[0], VecX::new([255, 0, 0]));
assert_eq!(indexed_colors[1], VecX::new([0, 255, 0]));

Elements of VecX must implement PartialEq,Eq,Hash. This is because we use HashSet internally. The Rust standard floating-point types do not implement Eq,Hash (due to NaN having multiple binary representations), so you cannot use f32 or f64.

VecXの要素はPartialEq,Eq,Hashを実装している必要があります。 これは内部でHashSetを使用しているためです。 Rust標準の浮動小数点数型はEq,Hashを実装していない(NaNが複数のバイナリ表現を持つことに起因する)ため、f32f64を使用することはできません。

If you want to handle floating point numbers, consider using ordered-float crates.

もし浮動小数点数を扱いたい場合、ordered-floatクレートを使用することを検討してください。

use vec_x::{VecX, IndexedVecXs};

let points: Vec<VecX<f64, 3>> = [
   [0., 0., 0.],
   [1., 0., 0.],
].into_iter().map(|p| VecX::new(p)).collect::<Vec<_>>();

let indexed_colors = IndexedVecXs::from_vec(points); // compile error

Fields§

§values: IndexSet<VecX<T, N>, FxBuildHasher>

unique set of `VecX

一意なVecXの集合

§indices: Vec<usize>

Index referring to values.

valuesを参照するインデックス

Implementations§

Source§

impl<T, const N: usize> IndexedVecXs<T, N>
where T: PartialEq + Eq + Hash + Sized + Send,

Source

pub fn new( values: IndexSet<VecX<T, N>, FxBuildHasher>, indices: Vec<usize>, ) -> Self

This is not normally used. Use from_vec to generate IndexedVecXs from Vec<VecX<T, N>>.

これは通常使用されません。Vec<VecX<T, N>>からIndexedVecXsを生成するためにはfrom_vecを使用してください。

Source

pub fn empty() -> Self

Generate empty IndexedVecXs.

空のIndexedVecXsを生成します。

Source

pub fn iter(&self) -> Vec<&VecX<T, N>>

Returns an iterable structure IndexedVecXIter. Internally, each time the iterator is consumed, it searches for the corresponding VecX from the values for the index in the indices.

イテレーション可能な構造体IndexedVecXIterを返します。 内部的には、イテレータが消費されるたびにvaluesからindices中のインデックスに対応するVecXを検索しています。

Source

pub fn from_vec(vec: Vec<VecX<T, N>>) -> Self

Generate IndexedVecXs from Vec<VecX<T, N>>.

Vec<VecX<T, N>>からIndexedVecXsを生成します。

Source

pub fn to_ref_vec(&self) -> Vec<&VecX<T, N>>

Generate Vec<&VecX<T, N>> from IndexedVecXs.

IndexedVecXsからVec<&VecX<T, N>>を生成します。

Source

pub fn insert(&mut self, value: VecX<T, N>) -> bool

Inserts a new element. Internally inserts a new element in values and adds its index to indices. Returns true if a new element is inserted into values.

新しい要素を挿入します。 内部的にはvaluesに新しい要素を挿入し、そのインデックスをindicesに追加します。 valuesに新しい要素が挿入された場合はtrueを返します。

Source§

impl<T, const N: usize> IndexedVecXs<T, N>
where T: PartialEq + Eq + Hash + Copy + Sized + Send,

Source

pub fn to_vec(self) -> Vec<VecX<T, N>>

Convert IndexedVecXs to Vec<VecX<T, N>.

IndexedVecXsVec<VecX<T, N>>に変換します。

Trait Implementations§

Source§

impl<T, const N: usize> Index<usize> for IndexedVecXs<T, N>
where T: PartialEq + Eq + Hash + Sized + Send,

Source§

type Output = VecX<T, N>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for IndexedVecXs<T, N>

§

impl<T, const N: usize> RefUnwindSafe for IndexedVecXs<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for IndexedVecXs<T, N>

§

impl<T, const N: usize> Sync for IndexedVecXs<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for IndexedVecXs<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for IndexedVecXs<T, N>
where 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.