pub struct Arena<T, I = (), V: Version = DefaultVersion> { /* private fields */ }Expand description
A sparse arena
Implementations§
Source§impl<T, I, V: Version> Arena<T, I, V>
impl<T, I, V: Version> Arena<T, I, V>
Sourcepub fn with_ident(ident: I) -> Self
pub fn with_ident(ident: I) -> Self
Create a new arena with the given identifier
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted
in the given collection. The collection may reserve more space to avoid
frequent reallocations. After calling reserve, capacity will be greater
than or equal to self.len() + additional. Does nothing if capacity is
already sufficient.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional more elements
to be inserted in the given collection. After calling reserve_exact,
capacity will be greater than or equal to self.len() + additional.
Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer reserve if future insertions are expected.
Sourcepub fn parse_key<K: BuildArenaKey<I, V>>(&self, index: usize) -> Option<K>
pub fn parse_key<K: BuildArenaKey<I, V>>(&self, index: usize) -> Option<K>
Check if an index is in bounds, and if it is return a Key<_, _> to it
Sourcepub fn vacant_entry(&mut self) -> VacantEntry<'_, T, I, V>
pub fn vacant_entry(&mut self) -> VacantEntry<'_, T, I, V>
Return a handle to a vacant entry allowing for further manipulation.
This function is useful when creating values that must contain their key. The returned VacantEntry reserves a slot in the arena and is able to query the associated key.
Sourcepub fn insert<K: BuildArenaKey<I, V>>(&mut self, value: T) -> K
pub fn insert<K: BuildArenaKey<I, V>>(&mut self, value: T) -> K
Insert a value in the arena, returning key assigned to the value.
The returned key can later be used to retrieve or remove the value using indexed lookup and remove. Additional capacity is allocated if needed.
Sourcepub fn contains<K: ArenaKey<I, V>>(&self, key: K) -> bool
pub fn contains<K: ArenaKey<I, V>>(&self, key: K) -> bool
Return true if a value is associated with the given key.
Sourcepub fn remove<K: ArenaKey<I, V>>(&mut self, key: K) -> T
pub fn remove<K: ArenaKey<I, V>>(&mut self, key: K) -> T
Remove and return the value associated with the given key.
The key is then released and may be associated with future stored values, if the versioning strategy allows it.
Panics if key is not associated with a value.
Sourcepub fn try_remove<K: ArenaKey<I, V>>(&mut self, key: K) -> Option<T>
pub fn try_remove<K: ArenaKey<I, V>>(&mut self, key: K) -> Option<T>
Remove and return the value associated with the given key.
The key is then released and may be associated with future stored values, if the versioning strategy allows it.
Returns None if key is not associated with a value.
Sourcepub fn delete<K: ArenaKey<I, V>>(&mut self, key: K) -> bool
pub fn delete<K: ArenaKey<I, V>>(&mut self, key: K) -> bool
Removes the value associated with the given key.
The key is then released and may be associated with future stored values, if the versioning strategy allows it.
Returns true if the value was removed, an false otherwise
Sourcepub fn get<K: ArenaKey<I, V>>(&self, key: K) -> Option<&T>
pub fn get<K: ArenaKey<I, V>>(&self, key: K) -> Option<&T>
Return a shared reference to the value associated with the given key.
If the given key is not associated with a value, then None is returned.
Sourcepub fn get_mut<K: ArenaKey<I, V>>(&mut self, key: K) -> Option<&mut T>
pub fn get_mut<K: ArenaKey<I, V>>(&mut self, key: K) -> Option<&mut T>
Return a unique reference to the value associated with the given key.
If the given key is not associated with a value, then None is returned.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &T
pub unsafe fn get_unchecked(&self, index: usize) -> &T
Return a shared reference to the value associated with the given key without performing bounds checking, or checks if there is a value associated to the key
§Safety
contains should return true with the given index.
Sourcepub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
Return a unique reference to the value associated with the given key without performing bounds checking, or checks if there is a value associated to the key
§Safety
contains should return true with the given index.
Sourcepub fn delete_all(&mut self)
pub fn delete_all(&mut self)
Deletes all elements from the arena
Sourcepub fn retain<F: FnMut(&mut T) -> bool>(&mut self, f: F)
pub fn retain<F: FnMut(&mut T) -> bool>(&mut self, f: F)
Retain only the elements specified by the predicate.
If the predicate returns for a given element true, then the element is kept in the arena.
Sourcepub fn keys<K: BuildArenaKey<I, V>>(&self) -> Keys<'_, T, I, V, K> ⓘ
pub fn keys<K: BuildArenaKey<I, V>>(&self) -> Keys<'_, T, I, V, K> ⓘ
An iterator over the keys of the arena, in no particular order
Sourcepub fn iter(&self) -> Iter<'_, T, V> ⓘ
pub fn iter(&self) -> Iter<'_, T, V> ⓘ
An iterator of shared references to values of the arena, in no particular order
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T, V> ⓘ
An iterator of unique references to values of the arena, in no particular order
Sourcepub fn drain(&mut self) -> Drain<'_, T, V> ⓘ
pub fn drain(&mut self) -> Drain<'_, T, V> ⓘ
Return a draining iterator that removes all elements from the arena and yields the removed items.
Note: Elements are removed even if the iterator is only partially consumed or not consumed at all.
Sourcepub fn drain_filter<F: FnMut(&mut T) -> bool>(
&mut self,
filter: F,
) -> DrainFilter<'_, T, V, F> ⓘ
pub fn drain_filter<F: FnMut(&mut T) -> bool>( &mut self, filter: F, ) -> DrainFilter<'_, T, V, F> ⓘ
Return a draining iterator that removes all elements specified by the predicate from the arena and yields the removed items.
If the predicate returns true for a given element, then it is removed from the arena, and yielded from the iterator.
Note: Elements are removed even if the iterator is only partially consumed or not consumed at all.
Sourcepub fn entries<K: BuildArenaKey<I, V>>(&self) -> Entries<'_, T, I, V, K> ⓘ
pub fn entries<K: BuildArenaKey<I, V>>(&self) -> Entries<'_, T, I, V, K> ⓘ
An iterator of keys and shared references to values of the arena, in no particular order, with each key being associated to the corrosponding value
Sourcepub fn entries_mut<K: BuildArenaKey<I, V>>(
&mut self,
) -> EntriesMut<'_, T, I, V, K> ⓘ
pub fn entries_mut<K: BuildArenaKey<I, V>>( &mut self, ) -> EntriesMut<'_, T, I, V, K> ⓘ
An iterator of keys and unique references to values of the arena, in no particular order, with each key being associated to the corrosponding value
Sourcepub fn into_entries<K: BuildArenaKey<I, V>>(self) -> IntoEntries<T, I, V, K> ⓘ
pub fn into_entries<K: BuildArenaKey<I, V>>(self) -> IntoEntries<T, I, V, K> ⓘ
An iterator of keys and values of the arena, in no particular order, with each key being associated to the corrosponding value
Trait Implementations§
Source§impl<T, I, V: Version> Extend<T> for Arena<T, I, V>
impl<T, I, V: Version> Extend<T> for Arena<T, I, V>
Source§fn extend<Iter: IntoIterator<Item = T>>(&mut self, iter: Iter)
fn extend<Iter: IntoIterator<Item = T>>(&mut self, iter: Iter)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)