pub struct IndexMap<T> { /* private fields */ }Expand description
A map from non-contiguous u32 keys to values of type T, which is
serialized and deserialized ascending order of the keys. Normally used for
relative dense maps with occasional “holes”, and stored as an array.
Implementations§
Source§impl<T> IndexMap<T>
impl<T> IndexMap<T>
Sourcepub fn with_capacity(_capacity: usize) -> IndexMap<T>
👎Deprecated
pub fn with_capacity(_capacity: usize) -> IndexMap<T>
Create an empty IndexMap, preallocating enough space to store
capacity entries without needing to reallocate the underlying memory.
§Note
Currently, this method has no effect and is equivalent to IndexMap::new call.
Sourcepub fn get(&self, idx: u32) -> Option<&T>
pub fn get(&self, idx: u32) -> Option<&T>
Return the name for the specified index, if it exists.
Sourcepub fn contains_key(&self, idx: u32) -> bool
pub fn contains_key(&self, idx: u32) -> bool
Does the map contain an entry for the specified index?
Sourcepub fn insert(&mut self, idx: u32, value: T) -> Option<T>
pub fn insert(&mut self, idx: u32, value: T) -> Option<T>
Insert a name into our map, returning the existing value if present.
Sourcepub fn iter(&self) -> impl Iterator<Item = (u32, &T)>
pub fn iter(&self) -> impl Iterator<Item = (u32, &T)>
Create a non-consuming iterator over this IndexMap’s keys and values.
Sourcepub fn deserialize_with<R, F>(
max_entry_space: usize,
deserialize_value: &F,
rdr: &mut R,
) -> Result<IndexMap<T>, Error>
pub fn deserialize_with<R, F>( max_entry_space: usize, deserialize_value: &F, rdr: &mut R, ) -> Result<IndexMap<T>, Error>
Custom deserialization routine.
We will allocate an underlying array no larger than max_entry_space to
hold the data, so the maximum index must be less than max_entry_space.
This prevents mallicious *.wasm files from having a single entry with
the index u32::MAX, which would consume far too much memory.
The deserialize_value function will be passed the index of the value
being deserialized, and must deserialize the value.
Source§impl<T> IndexMap<T>
impl<T> IndexMap<T>
Sourcepub fn deserialize<R: Read>(
max_entry_space: usize,
rdr: &mut R,
) -> Result<Self, Error>
pub fn deserialize<R: Read>( max_entry_space: usize, rdr: &mut R, ) -> Result<Self, Error>
Deserialize a map containing simple values that support Deserialize.
We will allocate an underlying array no larger than max_entry_space to
hold the data, so the maximum index must be less than max_entry_space.
Trait Implementations§
Source§impl<T> FromIterator<(u32, T)> for IndexMap<T>
impl<T> FromIterator<(u32, T)> for IndexMap<T>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = (u32, T)>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = (u32, T)>,
Create an IndexMap from an iterator.
Note: This API is designed for reasonably dense indices based on valid
data. Inserting a huge idx will use up a lot of RAM, and this function
will not try to protect you against that.