pub struct DirectIdMap<K: IntegerId, V> { /* private fields */ }Expand description
A map implemented as a Vec<Option<T>>,
which takes space proportional to the size of the maximum id.
There is no entry API because the overhead of lookups is very small.
Implementations§
Source§impl<K: IntegerId, V> DirectIdMap<K, V>
impl<K: IntegerId, V> DirectIdMap<K, V>
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Trim unused capacity.
Sourcepub fn contains_key(&self, id: impl EquivalentId<K>) -> bool
pub fn contains_key(&self, id: impl EquivalentId<K>) -> bool
Check if the specified key is present in the map.
Sourcepub fn get(&self, id: impl EquivalentId<K>) -> Option<&V>
pub fn get(&self, id: impl EquivalentId<K>) -> Option<&V>
Get the value associated with the specified key, or None if missing.
Sourcepub fn get_mut(&mut self, id: impl EquivalentId<K>) -> Option<&mut V>
pub fn get_mut(&mut self, id: impl EquivalentId<K>) -> Option<&mut V>
Get a mutable reference to the value associated with the specified key,
or None if missing.
Sourcepub fn insert(&mut self, id: K, value: V) -> Option<V>
pub fn insert(&mut self, id: K, value: V) -> Option<V>
Insert a key and a value, returning the previous value.
Sourcepub fn remove(&mut self, id: impl EquivalentId<K>) -> Option<V>
pub fn remove(&mut self, id: impl EquivalentId<K>) -> Option<V>
Remove a value associated with the given, returning the previous value ifp resent.
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Iterate over the key-value pairs in the map.
Guaranteed to be sorted by the integer id of the key.
Trait Implementations§
Source§impl<K: Clone + IntegerId, V: Clone> Clone for DirectIdMap<K, V>
impl<K: Clone + IntegerId, V: Clone> Clone for DirectIdMap<K, V>
Source§fn clone(&self) -> DirectIdMap<K, V>
fn clone(&self) -> DirectIdMap<K, V>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<K: IntegerId, V> Default for DirectIdMap<K, V>
impl<K: IntegerId, V> Default for DirectIdMap<K, V>
Source§impl<'de, K, V> Deserialize<'de> for DirectIdMap<K, V>
impl<'de, K, V> Deserialize<'de> for DirectIdMap<K, V>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a, K: IntegerId, V: Clone> Extend<(K, &'a V)> for DirectIdMap<K, V>
impl<'a, K: IntegerId, V: Clone> Extend<(K, &'a V)> for DirectIdMap<K, V>
Source§fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, &'a V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<K: IntegerId, V> Extend<(K, V)> for DirectIdMap<K, V>
impl<K: IntegerId, V> Extend<(K, V)> for DirectIdMap<K, V>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a, K: IntegerId, V: Clone> FromIterator<(K, &'a V)> for DirectIdMap<K, V>
impl<'a, K: IntegerId, V: Clone> FromIterator<(K, &'a V)> for DirectIdMap<K, V>
Source§impl<K: IntegerId, V> FromIterator<(K, V)> for DirectIdMap<K, V>
impl<K: IntegerId, V> FromIterator<(K, V)> for DirectIdMap<K, V>
Source§impl<K: IntegerId, V> Index<K> for DirectIdMap<K, V>
impl<K: IntegerId, V> Index<K> for DirectIdMap<K, V>
Source§impl<K: IntegerId, V> IndexMut<K> for DirectIdMap<K, V>
impl<K: IntegerId, V> IndexMut<K> for DirectIdMap<K, V>
Source§impl<'a, K: IntegerId, V> IntoIterator for &'a DirectIdMap<K, V>
impl<'a, K: IntegerId, V> IntoIterator for &'a DirectIdMap<K, V>
Source§impl<'a, K: IntegerId, V> IntoIterator for &'a mut DirectIdMap<K, V>
impl<'a, K: IntegerId, V> IntoIterator for &'a mut DirectIdMap<K, V>
Source§impl<K: IntegerId, V> IntoIterator for DirectIdMap<K, V>
impl<K: IntegerId, V> IntoIterator for DirectIdMap<K, V>
Source§impl<K, V> Serialize for DirectIdMap<K, V>
impl<K, V> Serialize for DirectIdMap<K, V>
impl<K: IntegerId, V: Eq> Eq for DirectIdMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for DirectIdMap<K, V>
impl<K, V> RefUnwindSafe for DirectIdMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for DirectIdMap<K, V>where
V: Send,
impl<K, V> Sync for DirectIdMap<K, V>where
V: Sync,
impl<K, V> Unpin for DirectIdMap<K, V>
impl<K, V> UnwindSafe for DirectIdMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.