Struct cranelift_entity::SparseMap[][src]

pub struct SparseMap<K, V> where
    K: EntityRef,
    V: SparseMapValue<K>, 
{ /* fields omitted */ }

A sparse mapping of entity references.

A SparseMap<K, V> map provides:

Compared to SecondaryMap

When should we use a SparseMap instead of a secondary SecondaryMap? First of all, SparseMap does not provide the functionality of a PrimaryMap which can allocate and assign entity references to objects as they are pushed onto the map. It is only the secondary entity maps that can be replaced with a SparseMap.

Implementations

impl<K, V> SparseMap<K, V> where
    K: EntityRef,
    V: SparseMapValue<K>, 
[src]

pub fn new() -> Self[src]

Create a new empty mapping.

pub fn len(&self) -> usize[src]

Returns the number of elements in the map.

pub fn is_empty(&self) -> bool[src]

Returns true is the map contains no elements.

pub fn clear(&mut self)[src]

Remove all elements from the mapping.

pub fn get(&self, key: K) -> Option<&V>[src]

Returns a reference to the value corresponding to the key.

pub fn get_mut(&mut self, key: K) -> Option<&mut V>[src]

Returns a mutable reference to the value corresponding to the key.

Note that the returned value must not be mutated in a way that would change its key. This would invalidate the sparse set data structure.

pub fn contains_key(&self, key: K) -> bool[src]

Return true if the map contains a value corresponding to key.

pub fn insert(&mut self, value: V) -> Option<V>[src]

Insert a value into the map.

If the map did not have this key present, None is returned.

If the map did have this key present, the value is updated, and the old value is returned.

It is not necessary to provide a key since the value knows its own key already.

pub fn remove(&mut self, key: K) -> Option<V>[src]

Remove a value from the map and return it.

pub fn pop(&mut self) -> Option<V>[src]

Remove the last value from the map.

pub fn values(&self) -> Iter<'_, V>[src]

Get an iterator over the values in the map.

The iteration order is entirely determined by the preceding sequence of insert and remove operations. In particular, if no elements were removed, this is the insertion order.

pub fn as_slice(&self) -> &[V][src]

Get the values as a slice.

Trait Implementations

impl<'a, K, V> IntoIterator for &'a SparseMap<K, V> where
    K: EntityRef,
    V: SparseMapValue<K>, 
[src]

Iterating over the elements of a set.

type Item = &'a V

The type of the elements being iterated over.

type IntoIter = Iter<'a, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<K, V> RefUnwindSafe for SparseMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V> Send for SparseMap<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for SparseMap<K, V> where
    K: Sync,
    V: Sync

impl<K, V> Unpin for SparseMap<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for SparseMap<K, V> where
    K: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.