differential_dataflow/algorithms/graphs/
propagate.rs1use std::hash::Hash;
4
5use timely::dataflow::*;
6
7use crate::{Collection, ExchangeData};
8use crate::lattice::Lattice;
9use crate::difference::{Abelian, Multiply};
10use crate::operators::arrange::arrangement::ArrangeByKey;
11
12pub fn propagate<G, N, L, R>(edges: &Collection<G, (N,N), R>, nodes: &Collection<G,(N,L),R>) -> Collection<G,(N,L),R>
18where
19 G: Scope<Timestamp: Lattice+Ord>,
20 N: ExchangeData+Hash,
21 R: ExchangeData+Abelian,
22 R: Multiply<R, Output=R>,
23 R: From<i8>,
24 L: ExchangeData,
25{
26 propagate_core(&edges.arrange_by_key(), nodes, |_label| 0)
27}
28
29pub fn propagate_at<G, N, L, F, R>(edges: &Collection<G, (N,N), R>, nodes: &Collection<G,(N,L),R>, logic: F) -> Collection<G,(N,L),R>
35where
36 G: Scope<Timestamp: Lattice+Ord>,
37 N: ExchangeData+Hash,
38 R: ExchangeData+Abelian,
39 R: Multiply<R, Output=R>,
40 R: From<i8>,
41 L: ExchangeData,
42 F: Fn(&L)->u64+Clone+'static,
43{
44 propagate_core(&edges.arrange_by_key(), nodes, logic)
45}
46
47use crate::trace::TraceReader;
48use crate::operators::arrange::arrangement::Arranged;
49
50pub fn propagate_core<G, N, L, Tr, F, R>(edges: &Arranged<G,Tr>, nodes: &Collection<G,(N,L),R>, logic: F) -> Collection<G,(N,L),R>
56where
57 G: Scope<Timestamp=Tr::Time>,
58 N: ExchangeData+Hash,
59 R: ExchangeData+Abelian,
60 R: Multiply<R, Output=R>,
61 R: From<i8>,
62 L: ExchangeData,
63 Tr: for<'a> TraceReader<Key<'a>=&'a N, Val<'a>=&'a N, Diff=R>+Clone+'static,
64 F: Fn(&L)->u64+Clone+'static,
65{
66 nodes.scope().iterative::<usize,_,_>(|scope| {
82
83 use crate::operators::reduce::ReduceCore;
84 use crate::operators::iterate::SemigroupVariable;
85 use crate::trace::implementations::{ValBuilder, ValSpine};
86
87 use timely::order::Product;
88
89 let edges = edges.enter(scope);
90 let nodes = nodes.enter_at(scope, move |r| 256 * (64 - (logic(&r.1)).leading_zeros() as usize));
91
92 let proposals = SemigroupVariable::new(scope, Product::new(Default::default(), 1usize));
93
94 let labels =
95 proposals
96 .concat(&nodes)
97 .reduce_abelian::<_,ValBuilder<_,_,_,_>,ValSpine<_,_,_,_>>("Propagate", |_, s, t| t.push((s[0].0.clone(), R::from(1_i8))));
98
99 let propagate: Collection<_, (N, L), R> =
100 labels
101 .join_core(&edges, |_k, l: &L, d| Some((d.clone(), l.clone())));
102
103 proposals.set(&propagate);
104
105 labels
106 .as_collection(|k,v| (k.clone(), v.clone()))
107 .leave()
108 })
109}