Trait oxidd_core::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§
sourcetype Iterator<'a>: Iterator<Item = &'a E>
where
Self: 'a,
E: 'a
type Iterator<'a>: Iterator<Item = &'a E> where Self: 'a, E: 'a
Iterator over Edges pointing to nodes at this level
sourcetype Taken: LevelView<E, N>
type Taken: LevelView<E, N>
Taken level view, see LevelView::take()
Required Methods§
sourcefn get(&self, node: &N) -> Option<&E>
fn get(&self, node: &N) -> Option<&E>
Get the edge corresponding to the given node (if present)
sourcefn insert(&mut self, edge: E) -> bool
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
NimplementsHasLevelandedgereferences a node for whichHasLevel::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.
sourcefn get_or_insert(&mut self, node: N) -> AllocResult<E>
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
nodeare stored in a different manager, or NimplementsHasLeveland [HasLevel::level(node)] returns a different level.
sourceunsafe fn gc(&mut self)
unsafe fn gc(&mut self)
Perform garbage collection on this level
§Safety
Must be called from inside the closure passed to Manager::reorder().
sourceunsafe fn remove(&mut self, node: &N) -> bool
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().
sourceunsafe fn swap(&mut self, other: &mut Self)
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!)