pub fn integrate(&self) -> Stream<Circuit<P>, D> {
        self.circuit()
            .cache_get_or_insert_with(IntegralId::new(self.local_node_id()), || {
                // Integration circuit:
                // ```
                //              input
                //   ┌─────────────────►
                //   │
                //   │    ┌───┐ current
                // ──┴───►│   ├────────►
                //        │ + │
                //   ┌───►│   ├────┐
                //   │    └───┘    │
                //   │             │
                //   │    ┌───┐    │
                //   │    │   │    │
                //   └────┤z-1├────┘
                //        │   │
                //        └───┴────────►
                //              delayed
                //              export
                // ```
                self.circuit().region("integrate", || {
                    let feedback = DelayedFeedback::new(self.circuit());
                    let integral = self.circuit().add_binary_operator_with_preference(
                        <Plus<D>>::new(),
                        feedback.stream(),
                        self,
                        OwnershipPreference::STRONGLY_PREFER_OWNED,
                        OwnershipPreference::PREFER_OWNED,
                    );
                    feedback.connect(&integral);
                    integral
                })
            })
            .clone()
    }
/// Integrate the input stream.
///
/// Computes the sum of values in the input stream.
///
/// # Examples
///
/// ```
/// # use dbsp::{
/// #     circuit::Root,
/// #     operator::Generator,
/// # };
/// let root = Root::build(move |circuit| {
///     // Generate a stream of 1's.
///     let stream = circuit.add_source(Generator::new(|| 1));
///     // Integrate the stream.
///     let integral = stream.integrate();
/// #   let mut counter1 = 0;
/// #   integral.inspect(move |n| { counter1 += 1; assert_eq!(*n, counter1) });
/// #   let mut counter2 = 0;
/// #   integral.delay().inspect(move |n| { assert_eq!(*n, counter2); counter2 += 1; });
/// })
/// .unwrap();
///
/// # for _ in 0..5 {
/// #     root.step().unwrap();
/// # }
/// ```
///
/// The above example generates the following input/output mapping:
///
/// ```text
/// input:  1, 1, 1, 1, 1, ...
/// output: 1, 2, 3, 4, 5, ...
/// ```
Integrate the input stream.
Computes the sum of values in the input stream.
Integrate the input stream . Computes the sum of values in the input stream .
pub fn integrate(&self) -> Stream<Circuit<P>, D> {
        self.circuit()
            .cache_get_or_insert_with(IntegralId::new(self.local_node_id()), || {
                // Integration circuit:
                // ```
                //              input
                //   ┌─────────────────►
                //   │
                //   │    ┌───┐ current
                // ──┴───►│   ├────────►
                //        │ + │
                //   ┌───►│   ├────┐
                //   │    └───┘    │
                //   │             │
                //   │    ┌───┐    │
                //   │    │   │    │
                //   └────┤z-1├────┘
                //        │   │
                //        └───┴────────►
                //              delayed
                //              export
                // ```
                self.circuit().region("integrate", || {
                    let feedback = DelayedFeedback::new(self.circuit());
                    let integral = self.circuit().add_binary_operator_with_preference(
                        <Plus<D>>::new(),
                        feedback.stream(),
                        self,
                        OwnershipPreference::STRONGLY_PREFER_OWNED,
                        OwnershipPreference::PREFER_OWNED,
                    );
                    feedback.connect(&integral);
                    integral
                })
            })
            .clone()
    }
pub fn integrate ( & self ) -> Stream < Circuit < P > , D > { self . circuit ( ) . cache_get_or_insert_with ( IntegralId :: new ( self . local_node_id ( ) ) , | | { // Integration circuit: // ``` //              input //   ┌─────────────────► //   │ //   │    ┌───┐ current // ──┴───►│   ├────────► //        │ + │ //   ┌───►│   ├────┐ //   │    └───┘    │ //   │             │ //   │    ┌───┐    │ //   │    │   │    │ //   └────┤z-1├────┘ //        │   │ //        └───┴────────► //              delayed //              export // ``` self . circuit ( ) . region ( " " , | | { let feedback = DelayedFeedback :: new ( self . circuit ( ) ) ; let integral = self . circuit ( ) . add_binary_operator_with_preference ( < Plus < D > > :: new ( ) , feedback . stream ( ) , self , OwnershipPreference :: STRONGLY_PREFER_OWNED , OwnershipPreference :: PREFER_OWNED , ) ; feedback . connect ( & integral ) ; integral } ) } ) . clone ( ) }
Integrate the input stream.
Integrate the input stream .
&self
examples
None
use dbsp::{
None
circuit::root,
None
operator::generator,
None
};
let root = Root::build(move |circuit| {
Generate a stream of 1's.
let stream = circuit.add_source(Generator::new(|| 1));
Integrate the stream.
let integral = stream.integrate().
let root = Root :: build ( move |circuit| { Generate a stream of 1 ' s . let stream = circuit . add_source ( Generator :: new ( || 1 )) ; Integrate the stream . let integral = stream . integrate () .
let mut counter1 = 0;
None
integral.inspect(move |n| { counter1 += 1; assert_eq!(*n, counter1) });
None
let mut counter2 = 0;
None
integral.delay().inspect(move |n| { assert_eq!(*n, counter2); counter2 += 1; });
None
for _ in 0..5 {
None
root.step().unwrap();
None
}


The above example generates the following input/output mapping.


The above example generates the following input / output mapping .