SparseIndexMap

Struct SparseIndexMap 

Source
pub struct SparseIndexMap<'a, K: IndexedValue + 'a, V, P: PointerFamily<'a>> { /* private fields */ }
Expand description

A mapping from indexed keys to values, implemented sparsely with a hash map.

This is more memory-efficient than the DenseIndexMap with a small number of keys.

Implementations§

Source§

impl<'a, K, V, P> SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>,

Source

pub fn new(domain: &P::Pointer<IndexedDomain<K>>) -> Self

Constructs an empty map within the given domain.

Source

pub fn get<M>(&self, key: impl ToIndex<K, M>) -> Option<&V>

Returns an immutable reference to a value for a given key if it exists.

Source

pub fn get_mut<M>(&mut self, key: impl ToIndex<K, M>) -> Option<&mut V>

Returns a mutable reference to a value for a given key if it exists.

Source

pub unsafe fn get_unchecked<M>(&self, key: impl ToIndex<K, M>) -> &V

Returns a reference to a value for a given key.

§Safety

This function has undefined behavior if key is not in self.

Source

pub unsafe fn get_unchecked_mut<M>(&mut self, key: impl ToIndex<K, M>) -> &mut V

Returns a mutable reference to a value for a given key.

§Safety

This function has undefined behavior if key is not in self.

Source

pub fn insert<M>(&mut self, key: impl ToIndex<K, M>, value: V)

Inserts the key/value pair into self.

Source

pub fn values(&self) -> impl ExactSizeIterator<Item = &V>

Returns an iterator over the values of the map.

Source

pub fn entry<M>(&mut self, key: impl ToIndex<K, M>) -> Entry<'_, K::Index, V>

Returns a mutable entry into the map for the given key.

Source

pub fn len(&self) -> usize

Returns the number of entries in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map has no elements.

Trait Implementations§

Source§

impl<'a, K, V, P, M, U> FromIndexicalIterator<'a, K, P, M, (U, V)> for SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>, U: ToIndex<K, M>,

Source§

fn from_indexical_iter( iter: impl Iterator<Item = (U, V)>, domain: &P::Pointer<IndexedDomain<K>>, ) -> Self

Converts an iterator into a collection within the given domain.
Source§

impl<'a, K, V, P> Index<<K as IndexedValue>::Index> for SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>,

Source§

type Output = V

The returned type after indexing.
Source§

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

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

impl<'a, K, V, P> IndexMut<<K as IndexedValue>::Index> for SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>,

Source§

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

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

impl<'a, 'b, K, V, P> IntoIterator for &'b SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a + 'b, V: 'b, P: PointerFamily<'a>,

Source§

type Item = (&'b <K as IndexedValue>::Index, &'b V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'b, <K as IndexedValue>::Index, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K, V, P> PartialEq for SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>, V: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, K, V, P> Eq for SparseIndexMap<'a, K, V, P>
where K: IndexedValue + 'a, P: PointerFamily<'a>, V: Eq,

Auto Trait Implementations§

§

impl<'a, K, V, P> Freeze for SparseIndexMap<'a, K, V, P>
where <P as PointerFamily<'a>>::Pointer<IndexedDomain<K>>: Freeze,

§

impl<'a, K, V, P> RefUnwindSafe for SparseIndexMap<'a, K, V, P>

§

impl<'a, K, V, P> Send for SparseIndexMap<'a, K, V, P>
where <P as PointerFamily<'a>>::Pointer<IndexedDomain<K>>: Send, <K as IndexedValue>::Index: Send, V: Send,

§

impl<'a, K, V, P> Sync for SparseIndexMap<'a, K, V, P>
where <P as PointerFamily<'a>>::Pointer<IndexedDomain<K>>: Sync, <K as IndexedValue>::Index: Sync, V: Sync,

§

impl<'a, K, V, P> Unpin for SparseIndexMap<'a, K, V, P>
where <P as PointerFamily<'a>>::Pointer<IndexedDomain<K>>: Unpin, <K as IndexedValue>::Index: Unpin, V: Unpin,

§

impl<'a, K, V, P> UnwindSafe for SparseIndexMap<'a, K, V, P>

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.