Skip to main content

Arena

Struct Arena 

Source
pub struct Arena<T, I = (), V: Version = DefaultVersion> { /* private fields */ }
Expand description

A sparse arena

Implementations§

Source§

impl<T> Arena<T>

Source

pub const fn new() -> Self

Create a new arena

Source§

impl<T, V: Version> Arena<T, (), V>

Source

pub const INIT: Self

An empty arena

Source

pub fn clear(&mut self)

Clear the arena without reducing it’s capacity

Source§

impl<T, I, V: Version> Arena<T, I, V>

Source

pub fn with_ident(ident: I) -> Self

Create a new arena with the given identifier

Source

pub fn ident(&self) -> &I

Get the associated identifier for this arena

Source

pub fn is_empty(&self) -> bool

Returns true if the arena is empty

Source

pub fn len(&self) -> usize

Returns the number of elements in this arena

Source

pub fn capacity(&self) -> usize

Returns the capacity of this arena

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

pub fn contains<K: ArenaKey<I, V>>(&self, key: K) -> bool

Return true if a value is associated with the given key.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn delete_all(&mut self)

Deletes all elements from the arena

Source

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.

Source

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

Source

pub fn iter(&self) -> Iter<'_, T, V>

An iterator of shared references to values of the arena, in no particular order

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T, V>

An iterator of unique references to values of the arena, in no particular order

Source

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.

Source

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.

Source

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

Source

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

Source

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: Clone, I: Clone, V: Clone + Version> Clone for Arena<T, I, V>

Source§

fn clone(&self) -> Arena<T, I, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, I: Debug, V: Debug + Version> Debug for Arena<T, I, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Arena<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, I, V: Version> Extend<T> for Arena<T, I, V>

Source§

fn extend<Iter: IntoIterator<Item = T>>(&mut self, iter: Iter)

Extends a collection with the contents of an iterator. Read more
Source§

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)

🔬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<T, I, V: Version, K: ArenaKey<I, V>> Index<K> for Arena<T, I, V>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: K) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, I, V: Version, K: ArenaKey<I, V>> IndexMut<K> for Arena<T, I, V>

Source§

fn index_mut(&mut self, key: K) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T, I, V: Version> IntoIterator for Arena<T, I, V>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, I, V> Freeze for Arena<T, I, V>
where I: Freeze,

§

impl<T, I, V> RefUnwindSafe for Arena<T, I, V>

§

impl<T, I, V> Send for Arena<T, I, V>
where I: Send, V: Send, T: Send,

§

impl<T, I, V> Sync for Arena<T, I, V>
where I: Sync, V: Sync, T: Sync,

§

impl<T, I, V> Unpin for Arena<T, I, V>
where I: Unpin, V: Unpin, T: Unpin,

§

impl<T, I, V> UnsafeUnpin for Arena<T, I, V>
where I: UnsafeUnpin,

§

impl<T, I, V> UnwindSafe for Arena<T, I, V>
where I: UnwindSafe, V: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.