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§
Sourcefn set_weight(&mut self, node: NodeIndex<Ix>, weight: W) -> Option<W>
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.
Sourcefn weight(&self, node: NodeIndex<Ix>) -> Option<&W>
fn weight(&self, node: NodeIndex<Ix>) -> Option<&W>
Immutably access the weight of the tree node indexed by node
.
Sourcefn subweight(&self, node: NodeIndex<Ix>) -> Option<&W>
fn subweight(&self, node: NodeIndex<Ix>) -> Option<&W>
Immutably access the subweight of the tree node indexed by node
.
Sourcefn adjust_weight(
&mut self,
node: NodeIndex<Ix>,
f: &dyn Fn(&mut W),
) -> Option<&W>
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.