use differential_dataflow::{ExchangeData, VecCollection, Hashable};
use differential_dataflow::difference::{Semigroup, Monoid, Multiply};
use differential_dataflow::operators::arrange::Arranged;
use differential_dataflow::trace::{BatchCursor, BatchDiff, BatchDiffGat, Cursor, Navigable, TraceReader};
pub fn propose<'scope, Tr, K, F, P, V>(
prefixes: VecCollection<'scope, Tr::Time, P, BatchDiff<Tr>>,
arrangement: Arranged<'scope, Tr>,
key_selector: F,
) -> VecCollection<'scope, Tr::Time, (P, V), BatchDiff<Tr>>
where
Tr: TraceReader<Batch: Navigable, Time: std::hash::Hash>+Clone+'static,
for<'a> BatchCursor<Tr>: Cursor<
Time = Tr::Time,
ValOwn = V,
Diff: Monoid+Multiply<Output = BatchDiff<Tr>>+ExchangeData+Semigroup<BatchDiffGat<'a, Tr>>,
>,
<BatchCursor<Tr> as Cursor>::KeyContainer: differential_dataflow::trace::implementations::BatchContainer<Owned=K>,
K: Hashable + Default + Ord + 'static,
F: Fn(&P)->K+Clone+'static,
P: ExchangeData,
V: Clone + 'static,
{
crate::operators::lookup_map(
prefixes,
arrangement,
move |p: &P, k: &mut K | { *k = key_selector(p); },
move |prefix, diff, value, sum| ((prefix.clone(), <BatchCursor<Tr> as Cursor>::owned_val(value)), diff.clone().multiply(sum)),
Default::default(),
Default::default(),
Default::default(),
)
}
pub fn propose_distinct<'scope, Tr, K, F, P, V>(
prefixes: VecCollection<'scope, Tr::Time, P, BatchDiff<Tr>>,
arrangement: Arranged<'scope, Tr>,
key_selector: F,
) -> VecCollection<'scope, Tr::Time, (P, V), BatchDiff<Tr>>
where
Tr: TraceReader<Batch: Navigable, Time: std::hash::Hash>+Clone+'static,
for<'a> BatchCursor<Tr>: Cursor<
Time = Tr::Time,
ValOwn = V,
Diff : Semigroup<BatchDiffGat<'a, Tr>>+Monoid+Multiply<Output = BatchDiff<Tr>>+ExchangeData,
>,
<BatchCursor<Tr> as Cursor>::KeyContainer: differential_dataflow::trace::implementations::BatchContainer<Owned=K>,
K: Hashable + Default + Ord + 'static,
F: Fn(&P)->K+Clone+'static,
P: ExchangeData,
V: Clone + 'static,
{
crate::operators::lookup_map(
prefixes,
arrangement,
move |p: &P, k: &mut K| { *k = key_selector(p); },
move |prefix, diff, value, _sum| ((prefix.clone(), <BatchCursor<Tr> as Cursor>::owned_val(value)), diff.clone()),
Default::default(),
Default::default(),
Default::default(),
)
}