[−][src]Struct cranelift_entity::PrimaryMap
A primary mapping K -> V
allocating dense entity references.
The PrimaryMap
data structure uses the dense index space to implement a map with a vector.
A primary map contains the main definition of an entity, and it can be used to allocate new
entity references with the push
method.
There should only be a single PrimaryMap
instance for a given EntityRef
type, otherwise
conflicting references will be created. Using unknown keys for indexing will cause a panic.
Note that PrimaryMap
doesn't implement Deref
or DerefMut
, which would allow
&PrimaryMap<K, V>
to convert to &[V]
. One of the main advantages of PrimaryMap
is
that it only allows indexing with the distinct EntityRef
key type, so converting to a
plain slice would make it easier to use incorrectly. To make a slice of a PrimaryMap
, use
into_boxed_slice
.
Methods
impl<K, V> PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
pub fn new() -> Self
[src]
Create a new empty map.
pub fn with_capacity(capacity: usize) -> Self
[src]
Create a new empty map with the given capacity.
pub fn is_valid(&self, k: K) -> bool
[src]
Check if k
is a valid key in the map.
pub fn get(&self, k: K) -> Option<&V>
[src]
Get the element at k
if it exists.
pub fn get_mut(&mut self, k: K) -> Option<&mut V>
[src]
Get the element at k
if it exists, mutable version.
pub fn is_empty(&self) -> bool
[src]
Is this map completely empty?
pub fn len(&self) -> usize
[src]
Get the total number of entity references created.
ⓘImportant traits for Keys<K>pub fn keys(&self) -> Keys<K>
[src]
Iterate over all the keys in this map.
pub fn values(&self) -> Iter<V>
[src]
Iterate over all the values in this map.
pub fn values_mut(&mut self) -> IterMut<V>
[src]
Iterate over all the values in this map, mutable edition.
ⓘImportant traits for Iter<'a, K, V>pub fn iter(&self) -> Iter<K, V>
[src]
Iterate over all the keys and values in this map.
ⓘImportant traits for IterMut<'a, K, V>pub fn iter_mut(&mut self) -> IterMut<K, V>
[src]
Iterate over all the keys and values in this map, mutable edition.
pub fn clear(&mut self)
[src]
Remove all entries from this map.
pub fn next_key(&self) -> K
[src]
Get the key that will be assigned to the next pushed value.
pub fn push(&mut self, v: V) -> K
[src]
Append v
to the mapping, assigning a new key which is returned.
pub fn last(&self) -> Option<&V>
[src]
Returns the last element that was inserted in the map.
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more elements to be inserted.
pub fn reserve_exact(&mut self, additional: usize)
[src]
Reserves the minimum capacity for exactly additional
more elements to be inserted.
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the capacity of the PrimaryMap
as much as possible.
pub fn into_boxed_slice(self) -> BoxedSlice<K, V>
[src]
Consumes this PrimaryMap
and produces a BoxedSlice
.
Trait Implementations
impl<K, V> Index<K> for PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
Immutable indexing into an PrimaryMap
.
The indexed value must be in the map.
impl<K, V> IndexMut<K> for PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
Mutable indexing into an PrimaryMap
.
impl<K: Debug, V: Debug> Debug for PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
impl<K, V> FromIterator<V> for PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = V>,
[src]
T: IntoIterator<Item = V>,
impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
type Item = (K, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
type Item = (K, &'a mut V)
The type of the elements being iterated over.
type IntoIter = IterMut<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<K: Clone, V: Clone> Clone for PrimaryMap<K, V> where
K: EntityRef,
[src]
K: EntityRef,
fn clone(&self) -> PrimaryMap<K, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<K, V> Unpin for PrimaryMap<K, V> where
K: Unpin,
V: Unpin,
K: Unpin,
V: Unpin,
impl<K, V> Send for PrimaryMap<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for PrimaryMap<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
impl<K, V> RefUnwindSafe for PrimaryMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> UnwindSafe for PrimaryMap<K, V> where
K: UnwindSafe,
V: UnwindSafe,
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
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>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
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>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,