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
use std::hash::Hash;
use timely::dataflow::*;
use ::{Collection, ExchangeData};
use ::operators::*;
use ::lattice::Lattice;
pub fn bfs<G, N>(edges: &Collection<G, (N,N)>, roots: &Collection<G, N>) -> Collection<G, (N,u32)>
where
G: Scope,
G::Timestamp: Lattice+Ord,
N: ExchangeData+Hash,
{
use operators::arrange::arrangement::ArrangeByKey;
let edges = edges.arrange_by_key();
bfs_arranged(&edges, roots)
}
use crate::trace::TraceReader;
use crate::operators::arrange::Arranged;
pub fn bfs_arranged<G, N, Tr>(edges: &Arranged<G, Tr>, roots: &Collection<G, N>) -> Collection<G, (N, u32)>
where
G: Scope,
G::Timestamp: Lattice+Ord,
N: ExchangeData+Hash,
Tr: TraceReader<Key=N, Val=N, Time=G::Timestamp, R=isize>+Clone+'static,
Tr::Batch: crate::trace::BatchReader<N, N, G::Timestamp, Tr::R>+'static,
Tr::Cursor: crate::trace::Cursor<N, N, G::Timestamp, Tr::R>+'static,
{
let nodes = roots.map(|x| (x, 0));
nodes.iterate(|inner| {
let edges = edges.enter(&inner.scope());
let nodes = nodes.enter(&inner.scope());
inner.join_core(&edges, |_k,l,d| Some((d.clone(), l+1)))
.concat(&nodes)
.reduce(|_, s, t| t.push((s[0].0.clone(), 1)))
})
}