Module differential_dataflow::operators::iterate
[−]
[src]
Iterative application of a differential dataflow fragment.
The iterate
operator takes as an argument a closure from a differential dataflow stream to a
stream of the same type. The output are differences which accumulate to the result of applying
this closure a specified number of times.
The implementation of iterate
does not directly apply the closure, but rather establishes an
iterative timely dataflow subcomputation, in which differences circulate until they dissipate
(indicating that the computation has reached fixed point), or until some number of iterations
have passed.
The iterate
method is written using a Variable
, which lets you define your own iterative
computations when iterate
itself is not sufficient. This can happen when you have two
collections that should evolve simultaneously, or when you would like to return an intermediate
result from your iterative computation.
Using Variable
requires more explicit arrangement of your computation, but isn't much more
complicated. You must define a new variable from an existing stream (its initial value), and
then set it to be a function of this variable (and perhaps other collections and variables).
A Variable
derefences to a Collection
, the one corresponding to its value in each iteration,
and it can be used in most situations where a collection can be used. The act of setting a
Variable
consumes it and returns the corresponding Collection
, preventing you from setting
it multiple times.
Examples
The example repeatedly divides even numbers by two, and leaves odd numbers as they are. Although some numbers may take multiple iterations to converge, converged numbers have no overhead in subsequent iterations.
// repeatedly divide out factors of two. let limits = numbers.iterate(|values| { values.map(|x if x % 2 == 0 { x/2 } else { x }) });
The same example written manually with a Variable
:
// repeatedly divide out factors of two. let limits = computation.scoped(|scope| { let variable = Variable::from(numbers.enter(scope)); let result = variable.map(|x if x % 2 == 0 { x/2 } else { x }); variable.set(&result) .leave() })
Structs
Variable |
A differential dataflow collection variable |
Traits
IterateExt |
An extension trait for the |