Trait LevelView

Source
pub unsafe trait LevelView<E: Edge, N: InnerNode<E>> {
    type Iterator<'a>: Iterator<Item = &'a E>
       where Self: 'a,
             E: 'a;
    type Taken: LevelView<E, N>;

    // Required methods
    fn len(&self) -> usize;
    fn level_no(&self) -> LevelNo;
    fn reserve(&mut self, additional: usize);
    fn get(&self, node: &N) -> Option<&E>;
    fn insert(&mut self, edge: E) -> bool;
    fn get_or_insert(&mut self, node: N) -> AllocResult<E>;
    unsafe fn gc(&mut self);
    unsafe fn remove(&mut self, node: &N) -> bool;
    unsafe fn swap(&mut self, other: &mut Self);
    fn iter(&self) -> Self::Iterator<'_>;
    fn take(&mut self) -> Self::Taken;

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

View of a single level in the manager

§Safety

Each level view is associated with a Manager M and a LevelNo L. The level view must ensure that all contained nodes and their descendants are stored in M. The edges returned by LevelView::get() and LevelView::get_or_insert() must reference nodes at this level. LevelView::iter() must yield all edges to nodes at this level (it must not hide some away).

LevelView::swap() conceptually removes all nodes from this level and inserts them at the other level and vice versa.

Required Associated Types§

Source

type Iterator<'a>: Iterator<Item = &'a E> where Self: 'a, E: 'a

Iterator over Edges pointing to nodes at this level

Source

type Taken: LevelView<E, N>

Taken level view, see LevelView::take()

Required Methods§

Source

fn len(&self) -> usize

Get the number of nodes on this level

Source

fn level_no(&self) -> LevelNo

Get the level number of this level

Source

fn reserve(&mut self, additional: usize)

Reserve space for additional nodes on this level

Source

fn get(&self, node: &N) -> Option<&E>

Get the edge corresponding to the given node (if present)

Source

fn insert(&mut self, edge: E) -> bool

Insert the given edge into the unique table at this level, assuming that the referenced node is already stored in the associated manager.

Returns true if the edge was inserted, false if it was already present.

Panics if edge

  • points to a terminal node,
  • references a node from a different manager, or
  • N implements HasLevel and edge references a node for which HasLevel::level() returns a different level.

Furthermore, this function should panic if edge is tagged, but the caller must not rely on that. An implementation may simply remove the tag for optimization purposes.

Source

fn get_or_insert(&mut self, node: N) -> AllocResult<E>

Get the edge corresponding to level and node if present, or insert it.

Panics if

  • the children of node are stored in a different manager, or
  • N implements HasLevel and [HasLevel::level(node)] returns a different level.
Source

unsafe fn gc(&mut self)

Perform garbage collection on this level

§Safety

Must be called from inside the closure passed to Manager::reorder().

Source

unsafe fn remove(&mut self, node: &N) -> bool

Remove node from (this level of) the manager

Returns whether the value was present at this level.

§Safety

Must be called from inside the closure passed to Manager::reorder().

Source

unsafe fn swap(&mut self, other: &mut Self)

Move all nodes from this level to the other level and vice versa.

§Safety

This method does not necessarily change the level returned by HasLevel::level() for the nodes at this or the other level. The caller must ensure a consistent state using calls to HasLevel::set_level(). (Be aware of exception safety!)

Source

fn iter(&self) -> Self::Iterator<'_>

Iterate over all the edges at this level

Source

fn take(&mut self) -> Self::Taken

Clear this level, returning a level view containing all the previous edges.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true iff this level contains nodes

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§