pub struct Variable<G: Scope, D: Data, R: Diff>where
    G::Timestamp: Lattice,
{ /* private fields */ }
Expand description

A recursively defined collection.

The Variable struct allows differential dataflow programs requiring more sophisticated iterative patterns than singly recursive iteration. For example: in mutual recursion two collections evolve simultaneously.

Examples

The following example is equivalent to the example for the Iterate trait.

extern crate timely;
extern crate differential_dataflow;

use timely::order::Product;
use timely::dataflow::Scope;

use differential_dataflow::input::Input;
use differential_dataflow::operators::iterate::Variable;
use differential_dataflow::operators::Consolidate;

fn main() {
    ::timely::example(|scope| {

        let numbers = scope.new_collection_from(1 .. 10u32).1;

        scope.iterative::<u64,_,_>(|nested| {
            let summary = Product::new(Default::default(), 1);
            let variable = Variable::new_from(numbers.enter(nested), summary);
            let result = variable.map(|x| if x % 2 == 0 { x/2 } else { x })
                                 .consolidate();
            variable.set(&result)
                    .leave()
        });
    })
}

Implementations

Creates a new initially empty Variable.

Creates a new Variable from a supplied source stream.

Adds a new source of data to the Variable.

Methods from Deref<Target = Collection<G, D, R>>

Creates a new collection by applying the supplied function to each input element.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map(|x| x * 2)
             .filter(|x| x % 2 == 1)
             .assert_empty();
    });
}

Creates a new collection by applying the supplied function to each input element.

Although the name suggests in-place mutation, this function does not change the source collection, but rather re-uses the underlying allocations in its implementation. The method is semantically equivalent to map, but can be more efficient.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map_in_place(|x| *x *= 2)
             .filter(|x| x % 2 == 1)
             .assert_empty();
    });
}

Creates a new collection by applying the supplied function to each input element and accumulating the results.

This method extracts an iterator from each input element, and extracts the full contents of the iterator. Be warned that if the iterators produce substantial amounts of data, they are currently fully drained before attempting to consolidate the results.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .flat_map(|x| 0 .. x);
    });
}

Creates a new collection whose counts are the negation of those in the input.

This method is most commonly used with concat to get those element in one collection but not another. However, differential dataflow computations are still defined for all values of the difference type R, including negative counts.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let odds = data.filter(|x| x % 2 == 1);
        let evens = data.filter(|x| x % 2 == 0);

        odds.negate()
            .concat(&data)
            .assert_eq(&evens);
    });
}

Creates a new collection containing those input records satisfying the supplied predicate.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map(|x| x * 2)
             .filter(|x| x % 2 == 1)
             .assert_empty();
    });
}

Creates a new collection accumulating the contents of the two collections.

Despite the name, differential dataflow collections are unordered. This method is so named because the implementation is the concatenation of the stream of updates, but it corresponds to the addition of the two collections.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let odds = data.filter(|x| x % 2 == 1);
        let evens = data.filter(|x| x % 2 == 0);

        odds.concat(&evens)
            .assert_eq(&data);
    });
}

Replaces each record with another, with a new difference type.

This method is most commonly used to take records containing aggregatable data (e.g. numbers to be summed) and move the data into the difference component. This will allow differential dataflow to update in-place.

#Examples

extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let nums = scope.new_collection_from(0 .. 10).1;
        let x1 = nums.flat_map(|x| 0 .. x);
        let x2 = nums.map(|x| (x, 9 - x))
                     .explode(|(x,y)| Some((x,y)));

        x1.assert_eq(&x2);
    });
}

Brings a Collection into a nested scope.

Examples
extern crate timely;
extern crate differential_dataflow;

use timely::dataflow::Scope;
use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let result = scope.region(|child| {
            data.enter(child)
                .leave()
        });

        data.assert_eq(&result);
    });
}

Brings a Collection into a nested scope, at varying times.

The initial function indicates the time at which each element of the Collection should appear.

Examples
extern crate timely;
extern crate differential_dataflow;

use timely::dataflow::Scope;
use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let result = scope.iterative::<u64,_,_>(|child| {
            data.enter_at(child, |x| *x)
                .leave()
        });

        data.assert_eq(&result);
    });
}

Delays each difference by a supplied function.

It is assumed that func only advances timestamps; this is not verified, and things may go horribly wrong if that assumption is incorrect. It is also critical that func be monotonic: if two times are ordered, they should have the same order once func is applied to them (this is because we advance the timely capability with the same logic, and it must remain less_equal to all of the data timestamps).

Applies a supplied function to each update.

This method is most commonly used to report information back to the user, often for debugging purposes. Any function can be used here, but be warned that the incremental nature of differential dataflow does not guarantee that it will be called as many times as you might expect.

The (data, time, diff) triples indicate a change diff to the frequency of data which takes effect at the logical time time. When times are totally ordered (for example, usize), these updates reflect the changes along the sequence of collections. For partially ordered times, the mathematics are more interesting and less intuitive, unfortunately.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map_in_place(|x| *x *= 2)
             .filter(|x| x % 2 == 1)
             .inspect(|x| println!("error: {:?}", x));
    });
}

Applies a supplied function to each batch of updates.

This method is analogous to inspect, but operates on batches and reveals the timestamp of the timely dataflow capability associated with the batch of updates. The observed batching depends on how the system executes, and may vary run to run.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map_in_place(|x| *x *= 2)
             .filter(|x| x % 2 == 1)
             .inspect_batch(|t,xs| println!("errors @ {:?}: {:?}", t, xs));
    });
}

Attaches a timely dataflow probe to the output of a Collection.

This probe is used to determine when the state of the Collection has stabilized and can be read out.

Attaches a timely dataflow probe to the output of a Collection.

This probe is used to determine when the state of the Collection has stabilized and all updates observed. In addition, a probe is also often use to limit the number of rounds of input in flight at any moment; a computation can wait until the probe has caught up to the input before introducing more rounds of data, to avoid swamping the system.

Assert if the collections are ever different.

Because this is a dataflow fragment, the test is only applied as the computation is run. If the computation is not run, or not run to completion, there may be un-exercised times at which the collections could vary. Typically, a timely dataflow computation runs to completion on drop, and so clean exit from a program should indicate that this assertion never found cause to complain.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let odds = data.filter(|x| x % 2 == 1);
        let evens = data.filter(|x| x % 2 == 0);

        odds.concat(&evens)
            .assert_eq(&data);
    });
}

Assert if the collection is ever non-empty.

Because this is a dataflow fragment, the test is only applied as the computation is run. If the computation is not run, or not run to completion, there may be un-exercised times at which the collection could be non-empty. Typically, a timely dataflow computation runs to completion on drop, and so clean exit from a program should indicate that this assertion never found cause to complain.

Examples
extern crate timely;
extern crate differential_dataflow;

use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {
        scope.new_collection_from(1 .. 10).1
             .map(|x| x * 2)
             .filter(|x| x % 2 == 1)
             .assert_empty();
    });
}

The scope containing the underlying timely dataflow stream.

Returns the final value of a Collection from a nested scope to its containing scope.

Examples
extern crate timely;
extern crate differential_dataflow;

use timely::dataflow::Scope;
use differential_dataflow::input::Input;

fn main() {
    ::timely::example(|scope| {

        let data = scope.new_collection_from(1 .. 10).1;

        let result = scope.region(|child| {
            data.enter(child)
                .leave()
        });

        data.assert_eq(&result);
    });
}

Trait Implementations

The resulting type after dereferencing.
Dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.