differential_dataflow/algorithms/graphs/
propagate.rs1use std::hash::Hash;
4
5use timely::progress::Timestamp;
6
7use crate::{VecCollection, ExchangeData};
8use crate::lattice::Lattice;
9use crate::difference::{Abelian, Multiply};
10
11pub fn propagate<'scope, T, N, L, R>(edges: VecCollection<'scope, T, (N,N), R>, nodes: VecCollection<'scope, T,(N,L),R>) -> VecCollection<'scope, T,(N,L),R>
17where
18 T: Timestamp + Lattice + Hash,
19 N: ExchangeData+Hash,
20 R: ExchangeData+Abelian,
21 R: Multiply<R, Output=R>,
22 R: From<i8>,
23 L: ExchangeData,
24{
25 propagate_core(edges.arrange_by_key(), nodes, |_label| 0)
26}
27
28pub fn propagate_at<'scope, T, N, L, F, R>(edges: VecCollection<'scope, T, (N,N), R>, nodes: VecCollection<'scope, T,(N,L),R>, logic: F) -> VecCollection<'scope, T,(N,L),R>
34where
35 T: Timestamp + Lattice + Hash,
36 N: ExchangeData+Hash,
37 R: ExchangeData+Abelian,
38 R: Multiply<R, Output=R>,
39 R: From<i8>,
40 L: ExchangeData,
41 F: Fn(&L)->u64+Clone+'static,
42{
43 propagate_core(edges.arrange_by_key(), nodes, logic)
44}
45
46use crate::trace::{BatchCursor, Cursor, Navigable, TraceReader};
47use crate::operators::arrange::arrangement::Arranged;
48
49pub fn propagate_core<'scope, N, L, Tr, F, R>(edges: Arranged<'scope, Tr>, nodes: VecCollection<'scope, Tr::Time,(N,L),R>, logic: F) -> VecCollection<'scope, Tr::Time,(N,L),R>
55where
56 N: ExchangeData+Hash,
57 R: ExchangeData+Abelian,
58 R: Multiply<R, Output=R>,
59 R: From<i8>,
60 L: ExchangeData,
61 Tr: TraceReader<Batch: Navigable, Time: Hash>+Clone+'static,
62 for<'a> BatchCursor<Tr>: Cursor<Key<'a>=&'a N, Val<'a>=&'a N, Time=Tr::Time, Diff=R>,
63 F: Fn(&L)->u64+Clone+'static,
64{
65 use timely::order::Product;
81 let outer = nodes.scope();
82 outer.scoped::<Product<_, usize>,_,_>("Propagate", |scope| {
83
84 use crate::operators::iterate::Variable;
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_bind, proposals) = Variable::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: VecCollection<_, (N, L), R> =
100 labels
101 .clone()
102 .join_core(edges, |_k, l: &L, d| Some((d.clone(), l.clone())));
103
104 proposals_bind.set(propagate);
105
106 labels
107 .as_collection(|k,v| (k.clone(), v.clone()))
108 .leave(outer)
109 })
110}