pub struct ForkTree<T> { /* private fields */ }
Expand description
Tree of nodes. Each node contains a value of type T
.
Implementations§
Source§impl<T> ForkTree<T>
impl<T> ForkTree<T>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Initializes a new ForkTree
with a certain pre-allocated capacity.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves additional capacity for at least additional
new blocks without allocating.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the capacity of the tree as much as possible.
Sourcepub fn iter_unordered(&self) -> impl Iterator<Item = (NodeIndex, &T)>
pub fn iter_unordered(&self) -> impl Iterator<Item = (NodeIndex, &T)>
Returns an iterator to all the node values without any specific order.
Sourcepub fn iter_ancestry_order(&self) -> impl Iterator<Item = (NodeIndex, &T)>
pub fn iter_ancestry_order(&self) -> impl Iterator<Item = (NodeIndex, &T)>
Returns an iterator to all the node values. The returned items are guaranteed to be in an order in which the parents are found before their children.
Sourcepub fn get(&self, index: NodeIndex) -> Option<&T>
pub fn get(&self, index: NodeIndex) -> Option<&T>
Returns the value of the node with the given index.
Sourcepub fn get_mut(&mut self, index: NodeIndex) -> Option<&mut T>
pub fn get_mut(&mut self, index: NodeIndex) -> Option<&mut T>
Returns the value of the node with the given index.
Sourcepub fn map<U>(self, map: impl FnMut(T) -> U) -> ForkTree<U>
pub fn map<U>(self, map: impl FnMut(T) -> U) -> ForkTree<U>
Modifies all the block user datas and returns a new map.
The returned tree keeps the same NodeIndex
es as self
.
Sourcepub fn prune_ancestors(
&mut self,
node_index: NodeIndex,
) -> PruneAncestorsIter<'_, T> ⓘ
pub fn prune_ancestors( &mut self, node_index: NodeIndex, ) -> PruneAncestorsIter<'_, T> ⓘ
Removes from the tree:
- The node passed as parameter.
- The ancestors of the node passed as parameter.
- Any node not a descendant of the node passed as parameter.
Returns an iterator containing the removed elements. All elements are removed from the tree even if the returned iterator is dropped eagerly.
Elements are returned in an unspecified order. However, each element yielded is guaranteed to be yielded before its parent gets yielded. This can be more or less called “reverse hierarchical order”.
In other words, doing prune_ancestors(...).filter(|n| n.is_prune_target_ancestor)
is
guaranteed to return the elements in the same order as ForkTree::node_to_root_path
does.
§Panic
Panics if the NodeIndex
is invalid.
Sourcepub fn prune_uncles(
&mut self,
node_index: NodeIndex,
) -> PruneAncestorsIter<'_, T> ⓘ
pub fn prune_uncles( &mut self, node_index: NodeIndex, ) -> PruneAncestorsIter<'_, T> ⓘ
Removes from the tree any node that isn’t either an ancestor or a descendant of the target node.
This function is similar to ForkTree::prune_ancestors
, except that all nodes returned
by the iterator are guaranteed to have PrunedNode::is_prune_target_ancestor
equal
to false
.
§Panic
Panics if the NodeIndex
is invalid.
Sourcepub fn is_ancestor(
&self,
maybe_ancestor: NodeIndex,
maybe_descendant: NodeIndex,
) -> bool
pub fn is_ancestor( &self, maybe_ancestor: NodeIndex, maybe_descendant: NodeIndex, ) -> bool
Sourcepub fn ascend_and_descend(
&self,
node1: NodeIndex,
node2: NodeIndex,
) -> (impl Iterator<Item = NodeIndex> + Clone, impl Iterator<Item = NodeIndex> + Clone)
pub fn ascend_and_descend( &self, node1: NodeIndex, node2: NodeIndex, ) -> (impl Iterator<Item = NodeIndex> + Clone, impl Iterator<Item = NodeIndex> + Clone)
Returns two iterators: the first iterator enumerates the nodes from node1
to the common
ancestor of node1
and node2
. The second iterator enumerates the nodes from that common
ancestor to node2
. The common ancestor isn’t included in either iterator. If node1
and
node2
are equal then both iterators are empty, otherwise node1
is always included in
the first iterator and node2
always included in the second iterator.
§Panic
Panics if one of the NodeIndex
s is invalid.
Sourcepub fn node_to_root_path(
&self,
node_index: NodeIndex,
) -> impl Iterator<Item = NodeIndex> + Clone
pub fn node_to_root_path( &self, node_index: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone
Sourcepub fn root_to_node_path(
&self,
node_index: NodeIndex,
) -> impl Iterator<Item = NodeIndex> + Clone
pub fn root_to_node_path( &self, node_index: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone
Same as ForkTree::node_to_root_path
, but gives the path in the reverse order.
§Panic
Panics if the NodeIndex
is invalid.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ForkTree<T>
impl<T> RefUnwindSafe for ForkTree<T>where
T: RefUnwindSafe,
impl<T> Send for ForkTree<T>where
T: Send,
impl<T> Sync for ForkTree<T>where
T: Sync,
impl<T> Unpin for ForkTree<T>where
T: Unpin,
impl<T> UnwindSafe for ForkTree<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more