TerminalManager

Trait TerminalManager 

Source
pub trait TerminalManager<'id, N, ET, const TERMINALS: usize>: Sized {
    type TerminalNode: Eq + Hash;
    type TerminalNodeRef<'a>: Borrow<Self::TerminalNode> + Copy
       where Self: 'a;
    type Iterator<'a>: Iterator<Item = Edge<'id, N, ET>>
       where Self: 'a;

    // Required methods
    fn with_capacity(capacity: u32) -> Self;
    fn len(&self) -> usize;
    unsafe fn get_terminal(&self, id: usize) -> Self::TerminalNodeRef<'_>;
    unsafe fn retain(&self, id: usize);
    unsafe fn release(&self, id: usize);
    fn get_edge(
        &self,
        terminal: Self::TerminalNode,
    ) -> AllocResult<Edge<'id, N, ET>>;
    fn iter<'a>(&'a self) -> Self::Iterator<'a>
       where Self: 'a;
    fn gc(&self) -> u32;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Manager for terminal nodes

Several methods of this trait require valid terminal node IDs. All Edges referencing terminal nodes “contain” valid terminal node IDs. These IDs can be derived from the edges by stripping the tags (which is an implementation detail of the manager module). Edges referencing terminal nodes are created by the get_edge() and iter() methods via Edge::from_terminal_id().

Required Associated Types§

Source

type TerminalNode: Eq + Hash

The terminal node type

Source

type TerminalNodeRef<'a>: Borrow<Self::TerminalNode> + Copy where Self: 'a

References to Self::TerminalNodes

Should either be a &'a Self::Terminal or just Self::Terminal. The latter is useful for the StaticTerminalManager which doesn’t actually store nodes but performs the mapping between edges and terminal nodes on the fly.

Source

type Iterator<'a>: Iterator<Item = Edge<'id, N, ET>> where Self: 'a

Iterator over all terminal nodes (as Edges), see Self::iter()

Required Methods§

Source

fn with_capacity(capacity: u32) -> Self

Create a new TerminalManager

capacity is a hint on the maximum number of terminal nodes and may be less than TERMINALS. If the number of terminals is constant, the implementation may simply ignore this parameter.

Source

fn len(&self) -> usize

Get the number of currently stored terminals

Source

unsafe fn get_terminal(&self, id: usize) -> Self::TerminalNodeRef<'_>

Get the terminal for id

§Safety

id must be a valid terminal node ID for this terminal manager.

Source

unsafe fn retain(&self, id: usize)

Increment the reference counter of the terminal id

§Safety

id must be a valid terminal node ID for this terminal manager.

Source

unsafe fn release(&self, id: usize)

Decrement the reference counter of the terminal id

§Safety

id must be a valid terminal node ID for this terminal manager.

Source

fn get_edge( &self, terminal: Self::TerminalNode, ) -> AllocResult<Edge<'id, N, ET>>

Add a terminal to this manager (if it does not already exist) and return an Edge pointing to it

Source

fn iter<'a>(&'a self) -> Self::Iterator<'a>
where Self: 'a,

Iterate over all terminals

Source

fn gc(&self) -> u32

Garbage collection: remove unused terminals

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true iff currently no terminals are stored

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'id, T, N, ET, const TERMINALS: usize> TerminalManager<'id, N, ET, TERMINALS> for DynamicTerminalManager<'id, T, N, ET, TERMINALS>
where T: Eq + Hash, N: NodeBase, ET: Tag,

Source§

type TerminalNode = T

Source§

type TerminalNodeRef<'a> = &'a T where Self: 'a

Source§

type Iterator<'a> = DynamicTerminalIterator<'a, 'id, T, N, ET> where Self: 'a, 'id: 'a

Source§

impl<'id, Terminal, InnerNode, EdgeTag, const TERMINALS: usize> TerminalManager<'id, InnerNode, EdgeTag, TERMINALS> for StaticTerminalManager<'id, Terminal, InnerNode, EdgeTag, TERMINALS>
where Terminal: Countable + Eq + Hash, InnerNode: NodeBase, EdgeTag: Tag,

Source§

type TerminalNode = Terminal

Source§

type TerminalNodeRef<'a> = Terminal where Self: 'a

Source§

type Iterator<'a> = StaticTerminalIterator<'id, InnerNode, EdgeTag> where Self: 'a, 'id: 'a