pub struct NodePool<'a> {
pub inner_vec: Vec<Node<'a>>,
pub counter: u32,
}
Expand description
Arena-based container storing Node
s
A NodePool
is essentially just a Vec<Node>
that is indexed by NodeID
s.
Each parsing construct stores NodeID
s which refer to indices within the NodePool
.
It acts like a flattened version of the AST where each node can be easily iterated over
and tracked.
NodePool::iter
and NodePool::iter_mut
can be used for iterating over the contents of
the pool.
§Safety
Removing or inserting an element at a position other than the end might invalidate every other NodeID
and therefore the AST. Removing and de-allocating an individual Node
is not possible due to
this effect. However, the result can be feigned in the tree by “deleting” the node from its parent.
See NodePool::delete_node
.
Fields§
§inner_vec: Vec<Node<'a>>
§counter: u32
Implementations§
Source§impl<'a> NodePool<'a>
impl<'a> NodePool<'a>
pub fn get(&self, id: NodeID) -> Option<&'a Node<'_>>
pub fn get_mut(&mut self, id: NodeID) -> Option<&'a mut Node<'_>>
pub fn iter( &self, ) -> impl Iterator<Item = &Node<'a>> + DoubleEndedIterator<Item = &Node<'a>>
pub fn iter_mut( &mut self, ) -> impl Iterator<Item = &mut Node<'a>> + DoubleEndedIterator<Item = &mut Node<'a>>
Sourcepub fn print_tree(&self)
pub fn print_tree(&self)
Outputs a (somewhat) legible representation of the tree to stdout.
Sourcepub fn delete_node(&mut self, index_id: NodeID)
pub fn delete_node(&mut self, index_id: NodeID)
Removes a Node
from its parents’ “children”.
This action mimicks the effect of a deletion, but does not actually deallocate or remove the node from the pool.