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
use crate::ExchangeData;
use crate::dataflow::{Stream, Scope};
use crate::dataflow::operators::{Map, Exchange};
pub trait Broadcast<D: ExchangeData> {
fn broadcast(&self) -> Self;
}
impl<G: Scope, D: ExchangeData> Broadcast<D> for Stream<G, D> {
fn broadcast(&self) -> Stream<G, D> {
let peers = self.scope().peers() as u64;
self.flat_map(move |x| (0 .. peers).map(move |i| (i,x.clone())))
.exchange(|ix| ix.0)
.map(|(_i,x)| x)
}
}