pub struct Fold<'a, T, U> {
pub step: &'a mut dyn FnMut(T, FoldNode<'_>) -> T,
pub initial: T,
pub extract: &'a dyn Fn(T, Option<(U, U)>) -> U,
}Expand description
Folds in the style of foldl on
hackage.
This performs specialized folds over FoldNode representations. With a
(currently non-existent) composition, one can perform multiple folds in a
single walk of the BDD.
See Fold::mut_fold’s documentation for an example of how to write this
style of fold.
Fields§
§step: &'a mut dyn FnMut(T, FoldNode<'_>) -> T§initial: TThe initial value for the aggregation.
extract: &'a dyn Fn(T, Option<(U, U)>) -> UHow to extract the final value U from a node. If a node has children,
provide the final outputs of their values as a tuple.
Implementations§
Source§impl<'a, T: Clone, U> Fold<'a, T, U>
impl<'a, T: Clone, U> Fold<'a, T, U>
Sourcepub fn new(
step: &'a mut dyn FnMut(T, FoldNode<'_>) -> T,
initial: T,
extract: &'a dyn Fn(T, Option<(U, U)>) -> U,
) -> Fold<'a, T, U>
pub fn new( step: &'a mut dyn FnMut(T, FoldNode<'_>) -> T, initial: T, extract: &'a dyn Fn(T, Option<(U, U)>) -> U, ) -> Fold<'a, T, U>
Construct a new Fold.
Sourcepub fn mut_fold(&mut self, bdd: &BddPtr<'_>) -> U
pub fn mut_fold(&mut self, bdd: &BddPtr<'_>) -> U
A mutable fold. An example of how to use this fold can be seen by collecting all VarLabels in the sub-tree referenced by a given BddPtr:
use rsdd::repr::VarLabel;
use rsdd::repr::BddPtr;
use rsdd::repr::Fold;
pub fn variables(bdd: BddPtr) -> Vec<VarLabel> {
Fold::new(
&mut |vs: Vec<Option<VarLabel>>, bdd| {
let mut vs = vs;
vs.push(bdd.node.var_safe());
vs
},
vec![],
&|ret, lo_hi| match lo_hi {
None => ret,
Some((lo, hi)) => {
let mut v = ret;
v.extend(lo);
v.extend(hi);
v
}
},
)
.mut_fold(&bdd)
.into_iter()
.flatten()
.collect()
}Auto Trait Implementations§
impl<'a, T, U> Freeze for Fold<'a, T, U>where
T: Freeze,
impl<'a, T, U> !RefUnwindSafe for Fold<'a, T, U>
impl<'a, T, U> !Send for Fold<'a, T, U>
impl<'a, T, U> !Sync for Fold<'a, T, U>
impl<'a, T, U> Unpin for Fold<'a, T, U>where
T: Unpin,
impl<'a, T, U> !UnwindSafe for Fold<'a, T, U>
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
Mutably borrows from an owned value. Read more