DenseIndexMap

Struct DenseIndexMap 

Source
pub struct DenseIndexMap<'a, K: IndexedValue + 'a, V, P: PointerFamily<'a>>(/* private fields */);
Expand description

A mapping from indexed keys to values, implemented densely with a vector.

This is more time-efficient than the SparseIndexMap for lookup, but it consumes more memory for missing elements.

Implementations§

Source§

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

Source

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

Constructs a new map with an initial element of mk_elem(i) for each i in domain.

Source

pub fn get<M>(&self, idx: 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, idx: 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, idx: 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, idx: 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, idx: impl ToIndex<K, M>, value: V)

Inserts the key/value pair into self.

Source

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

Returns an iterator over the values of the map.

Trait Implementations§

Source§

impl<'a, K, V, P, M, U> FromIndexicalIterator<'a, K, P, M, (U, V)> for DenseIndexMap<'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 DenseIndexMap<'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 DenseIndexMap<'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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, K, V, P> UnwindSafe for DenseIndexMap<'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.