Expand description
Arenas are efficient ways of storing trees: All nodes are actually on a flat surface, but have IDs to other nodes.
Variants§
Implementations§
source§impl<'a, T> Arena<'a, T>
impl<'a, T> Arena<'a, T>
sourcepub fn with_arena(arena: &'a mut Vec<Option<T>>) -> Self
pub fn with_arena(arena: &'a mut Vec<Option<T>>) -> Self
Create a new arena instance that reuses an existing vector
sourcepub fn reference<'b>(&'b mut self) -> Arena<'b, T>
pub fn reference<'b>(&'b mut self) -> Arena<'b, T>
Create a new arena reference that shares the inner vector. This reference will make the existing instance invalid for use while the reference is active.
sourcepub fn into_inner(self) -> Vec<Option<T>>
pub fn into_inner(self) -> Vec<Option<T>>
sourcepub fn get_ref(&self) -> &[Option<T>]
pub fn get_ref(&self) -> &[Option<T>]
Return a slice pointing to the inner arena representation
sourcepub fn take(&mut self, index: NodeId) -> T
pub fn take(&mut self, index: NodeId) -> T
Move out of an element in the arena. This will make following indexing calls on that index panic. This will not deallocate any space. This is due to the fact that all indexes need to stay the same. We could use a different data type instead of a tree to prevent this, but that instead means lookup will be slightly slower.