Struct ForkTree

Source
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>

Source

pub fn new() -> Self

Initializes a new ForkTree.

Source

pub fn with_capacity(cap: usize) -> Self

Initializes a new ForkTree with a certain pre-allocated capacity.

Source

pub fn reserve(&mut self, additional: usize)

Reserves additional capacity for at least additional new blocks without allocating.

Source

pub fn clear(&mut self)

Removes all elements in the tree, leaving it empty.

Source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the tree as much as possible.

Source

pub fn is_empty(&self) -> bool

Returns true if there isn’t any element in the tree.

Source

pub fn len(&self) -> usize

Returns the number of elements in the tree.

Source

pub fn iter_unordered(&self) -> impl Iterator<Item = (NodeIndex, &T)>

Returns an iterator to all the node values without any specific order.

Source

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.

Source

pub fn contains(&self, index: NodeIndex) -> bool

Returns true if the given NodeIndex is valid.

Source

pub fn get(&self, index: NodeIndex) -> Option<&T>

Returns the value of the node with the given index.

Source

pub fn get_mut(&mut self, index: NodeIndex) -> Option<&mut T>

Returns the value of the node with the given index.

Source

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 NodeIndexes as self.

Source

pub fn ancestors(&self, node: NodeIndex) -> impl Iterator<Item = NodeIndex>

Returns the ancestors of the given node. The iterator is empty if the node doesn’t have any parent.

§Panic

Panics if the NodeIndex is invalid.

Source

pub fn parent(&self, node: NodeIndex) -> Option<NodeIndex>

Returns the parent of the given node. Returns None if the node doesn’t have any parent.

§Panic

Panics if the NodeIndex is invalid.

Source

pub fn children( &self, node: Option<NodeIndex>, ) -> impl Iterator<Item = NodeIndex>

Returns the list of children that have the given node as parent.

§Panic

Panics if the NodeIndex is invalid.

Source

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.

Source

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.

Source

pub fn common_ancestor( &self, node1: NodeIndex, node2: NodeIndex, ) -> Option<NodeIndex>

Returns the common ancestor between node1 and node2, if any is known.

§Panic

Panics if one of the NodeIndexs is invalid.

Source

pub fn is_ancestor( &self, maybe_ancestor: NodeIndex, maybe_descendant: NodeIndex, ) -> bool

Returns true if maybe_ancestor is an ancestor of maybe_descendant. Also returns true if the two NodeIndex are equal.

§Panic

Panics if one of the NodeIndexs is invalid.

Source

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 NodeIndexs is invalid.

Source

pub fn node_to_root_path( &self, node_index: NodeIndex, ) -> impl Iterator<Item = NodeIndex> + Clone

Enumerates all the nodes, starting from the given node, to the root. Each element returned by the iterator is a parent of the previous one. The iterator does include the node itself.

§Panic

Panics if the NodeIndex is invalid.

Source

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.

Source

pub fn find(&self, cond: impl FnMut(&T) -> bool) -> Option<NodeIndex>

Finds the first node in the tree that matches the given condition.

Source

pub fn insert(&mut self, parent: Option<NodeIndex>, child: T) -> NodeIndex

Inserts a new node in the tree.

§Panic

Panics if parent isn’t a valid node index.

Trait Implementations§

Source§

impl<T> Debug for ForkTree<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for ForkTree<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V