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>;
fn gc(&mut self);
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 NimplementsHasLevelandHasLevel::level(node)returns a different level.
Sourcefn gc(&mut self)
fn gc(&mut self)
Perform garbage collection on this level
This method may be a no-op unless a garbage collection has been
prepared. For instance, this is what Manager::reorder() does.
Sourcefn remove(&mut self, node: &N) -> bool
fn remove(&mut self, node: &N) -> bool
Remove node from (this level of) the manager
Returns whether the node was present at this level and has been removed.
This method may be a no-op unless a garbage collection has been
prepared. For instance, this is what Manager::reorder() does. In the
no-op case, the return value is always false.
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!)
Provided Methods§
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.