Fold

Struct Fold 

Source
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

FnMut step which takes in an aggregation T and a node representation FoldNode.

§initial: T

The initial value for the aggregation.

§extract: &'a dyn Fn(T, Option<(U, U)>) -> U

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

Source

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.

Source

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