Trait WeightedTree

Source
pub trait WeightedTree<W, Ix = DefaultIndexType>
where W: WeightType, Ix: IndexType,
{ // Required methods fn set_weight(&mut self, node: NodeIndex<Ix>, weight: W) -> Option<W>; fn weight(&self, node: NodeIndex<Ix>) -> Option<&W>; fn subweight(&self, node: NodeIndex<Ix>) -> Option<&W>; fn adjust_weight( &mut self, node: NodeIndex<Ix>, f: &dyn Fn(&mut W), ) -> Option<&W>; }
Expand description

Trees implementing this trait are able to maintain node weights and subweights. The subweight of a tree node is recursively defined as the sum of its own weight plus the subweights of its children. The subweight of a leaf node is equal to its weight.

Required Methods§

Source

fn set_weight(&mut self, node: NodeIndex<Ix>, weight: W) -> Option<W>

Set the weight of the tree node indexed by node to weight and update the subweight of this node as well as the subweights of the nodes on the path from this node to the tree root. If node was a valid index, the old weight is returned.

Source

fn weight(&self, node: NodeIndex<Ix>) -> Option<&W>

Immutably access the weight of the tree node indexed by node.

Source

fn subweight(&self, node: NodeIndex<Ix>) -> Option<&W>

Immutably access the subweight of the tree node indexed by node.

Source

fn adjust_weight( &mut self, node: NodeIndex<Ix>, f: &dyn Fn(&mut W), ) -> Option<&W>

Change the weight of the tree node indexed by node by applying the closure f. After applying the closure, the subweight of this node as well as the subweights of the nodes on the path from this node to the tree root will be updated accordingly. If node was a valid index a reference to the changed weight is returned.

Implementors§

Source§

impl<K, V, W> WeightedTree<W> for WeightedAaTree<K, V, W>
where K: KeyType, V: ValueType, W: WeightType,

Source§

impl<V, W> WeightedTree<W> for WeightedAaForest<V, W>
where V: ValueType, W: WeightType,