DefaultSparseVec

Struct DefaultSparseVec 

Source
pub struct DefaultSparseVec<T: Default + PartialEq + Clone> { /* private fields */ }
Expand description

のdefault値をスパースするSparseVectorの実装 Vecの実装を参考にします src : https://doc.rust-jp.rs/rust-nomicon-ja/vec.html : https://doc.rust-lang.org/std/vec/struct.Vec.html

Implementations§

Source§

impl<T: Default + PartialEq + Clone> DefaultSparseVec<T>

Source

pub fn new() -> Self

newメソッドの実装

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

capacityメソッドの実装 スパースベクトルの現在の容量を取得

Source

pub fn reserve(&mut self, additional: usize)

reserveメソッドの実装 スパースベクトルの容量を増やす 既に確保されている容量よりも小さい場合は何もしない 既に確保されている容量よりも大きい場合は、新しい容量に再確保する

Source

pub fn shrink_to_fit(&mut self)

shrink_to_fitメソッドの実装 スパースベクトルの容量を現在の長さに合わせる 既に確保されている容量と現在の長さが同じ場合は何もしない

Source

pub fn nnz(&self) -> usize

nnzメソッドの実装 スパースベクトル長の取得

Source

pub fn len(&self) -> usize

lenメソッドの実装

Source

pub fn clear(&mut self)

clearメソッドの実装

Source

pub fn push(&mut self, elem: T)

pushメソッドの実装

Source

pub fn pop(&mut self) -> Option<T>

popメソッドの実装

Source

pub fn get(&self, index: usize) -> Option<&T>

getメソッドの実装

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

👎Deprecated: このメソッドは避けるべきです. スパース分部の実値を渡すため、スパース分部の値を無駄に生成します. default値以外を代入する場合は問題ありません.
Source

pub fn insert(&mut self, index: usize, elem: T)

insertメソッド 「index 番目に新しい要素を割り込む」という動作

  • 後続要素のインデックスは常に +1 シフト
  • elem が非デフォルト値なら物理領域に書き込む (raw_len += 1)
  • elem がデフォルト値なら物理領域には書き込まない(スパース化)
Source

pub fn remove(&mut self, index: usize) -> T

removeメソッド

index 番目の要素を削除し、削除した要素を返します。

  • 論理インデックス index が物理的に存在すれば、その値を返す
  • 物理的になければ(= デフォルト扱いだった)デフォルト値を返す

いずれにせよ後ろの要素(論理インデックスが index より大きい要素)は インデックスを 1 つ前にシフトします。

Source

pub fn append(&mut self, other: Self)

2つのスパースベクタを “連結” する append 実装例

  • other は消費 (ムーブ) して、自分に要素をつけ足す
  • other のインデックスは自分の len 分だけシフト
Source

pub fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = T>,

extendメソッドの実装

Source

pub fn iter(&self) -> impl Iterator<Item = (&usize, &T)>

iterメソッドの実装(仮) スパース分部を含みません スパース分部が必要な場合はNormalVecMethods trait実装

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&mut usize, &mut T)>

iter_mutメソッドの実装(仮) スパース分部を含みません スパース分部が必要な場合はNormalVecMethods trait実装

Source

pub fn as_slice_val(&self) -> &[T]

Source

pub fn as_slice_ind(&self) -> &[usize]

Source

pub fn as_mut_slice_val(&mut self) -> &mut [T]

Source

pub fn as_mut_slice_ind(&mut self) -> &mut [usize]

Trait Implementations§

Source§

impl<T: Default + PartialEq + Clone> Clone for DefaultSparseVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Default + PartialEq + Clone + Debug> Debug for DefaultSparseVec<T>

Source§

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

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

impl<T: Default + PartialEq + Clone> Default for DefaultSparseVec<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Default + PartialEq + Clone> Drop for DefaultSparseVec<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Default + PartialEq + Clone> From<HashMap<usize, T>> for DefaultSparseVec<T>

Source§

fn from(map: HashMap<usize, T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Default + PartialEq + Clone> From<Vec<T>> for DefaultSparseVec<T>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Default + PartialEq + Clone> Index<usize> for DefaultSparseVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T: Default + PartialEq + Clone> IndexMut<usize> for DefaultSparseVec<T>

Source§

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

#warning このメソッドは、非推奨のget_mutメソッドを使用しています

Source§

impl<T: Default + PartialEq + Clone> Into<HashMap<usize, T>> for DefaultSparseVec<T>

Source§

fn into(self) -> HashMap<usize, T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: Default + PartialEq + Clone> Into<Vec<T>> for DefaultSparseVec<T>

Source§

fn into(self) -> Vec<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T> Math<T> for DefaultSparseVec<T>
where T: Num + Default + PartialEq + Clone + AddAssign + Mul<Output = T> + Into<u64>,

Source§

fn u64_dot(&self, other: &Self) -> u64

Source§

fn u128_dot(&self, other: &Self) -> u128

Source§

fn u32_dot(&self, other: &Self) -> u32

Source§

fn u16_dot(&self, other: &Self) -> u16

Source§

fn u8_dot(&self, other: &Self) -> u8

Source§

fn i128_dot(&self, other: &Self) -> i128

Source§

fn i64_dot(&self, other: &Self) -> i64

Source§

fn i32_dot(&self, other: &Self) -> i32

Source§

fn i16_dot(&self, other: &Self) -> i16

Source§

fn i8_dot(&self, other: &Self) -> i8

Source§

fn f64_dot(&self, other: &Self) -> f64

Source§

fn f32_dot(&self, other: &Self) -> f32

Source§

impl<T: Default + PartialEq + Clone> NormalVecMethods<T> for DefaultSparseVec<T>

Source§

fn n_push(&mut self, elem: T)

Source§

fn n_pop(&mut self) -> Option<T>

Source§

fn n_insert(&mut self, index: usize, elem: T)

Source§

impl<T: Send + Default + PartialEq + Clone> Send for DefaultSparseVec<T>

Source§

impl<T: Send + Default + PartialEq + Clone> Sync for DefaultSparseVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for DefaultSparseVec<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for DefaultSparseVec<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for DefaultSparseVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for DefaultSparseVec<T>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.