1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Directed label reachability.

use std::hash::Hash;

use timely::dataflow::*;

use ::{Collection, ExchangeData};
use ::operators::*;
use ::lattice::Lattice;

/// Propagates labels forward, retaining the minimum label.
pub fn propagate<G, N, L>(edges: &Collection<G, (N,N)>, nodes: &Collection<G,(N,L)>) -> Collection<G,(N,L)>
where
    G: Scope,
    G::Timestamp: Lattice+Ord,
    N: ExchangeData+Hash,
    L: ExchangeData,
{
    nodes.filter(|_| false)
         .iterate(|inner| {
             let edges = edges.enter(&inner.scope());
             let nodes = nodes.enter(&inner.scope());

             inner.join_map(&edges, |_k,l,d| (d.clone(),l.clone()))
                  .concat(&nodes)
                  .reduce(|_, s, t| t.push((s[0].0.clone(), 1)))

         })
}

/// Propagates labels forward, retaining the minimum label.
pub fn propagate_at<G, N, L, F>(edges: &Collection<G, (N,N)>, nodes: &Collection<G,(N,L)>, logic: F) -> Collection<G,(N,L)>
where
    G: Scope,
    G::Timestamp: Lattice+Ord,
    N: ExchangeData+Hash,
    L: ExchangeData,
    F: Fn(&L)->u64+'static,
{
    nodes.filter(|_| false)
         .iterate(|inner| {
             let edges = edges.enter(&inner.scope());
             let nodes = nodes.enter_at(&inner.scope(), move |r| 256 * (64 - (logic(&r.1)).leading_zeros() as u64));

             inner.join_map(&edges, |_k,l,d| (d.clone(),l.clone()))
                  .concat(&nodes)
                  .reduce(|_, s, t| t.push((s[0].0.clone(), 1)))

         })
}