-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add size_hint to windows and collect_to operator
- Loading branch information
Showing
8 changed files
with
546 additions
and
32 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,63 @@ | ||
/// TODO | ||
|
||
use super::super::*; | ||
use crate::operator::{Data, DataKey, Operator}; | ||
use crate::stream::{KeyedStream, WindowedStream}; | ||
|
||
#[derive(Clone)] | ||
struct CollectVec<I, O, F> | ||
struct CollectTo<I, O> | ||
where | ||
F: Fn(Vec<I>) -> O, | ||
O: Extend<I> + Default, | ||
{ | ||
vec: Vec<I>, | ||
f: F, | ||
_o: PhantomData<O>, | ||
collection: O, | ||
_i: PhantomData<I>, | ||
} | ||
|
||
impl<I, O> Clone for CollectTo<I, O> | ||
where | ||
O: Extend<I> + Default, | ||
{ | ||
fn clone(&self) -> Self { | ||
Self { | ||
collection: Default::default(), | ||
_i: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<I, O, F> WindowAccumulator for CollectVec<I, O, F> | ||
impl<I, O> WindowAccumulator for CollectTo<I, O> | ||
where | ||
F: Fn(Vec<I>) -> O + Send + Clone + 'static, | ||
O:, | ||
I: Clone + Send + 'static, | ||
O: Clone + Send + 'static, | ||
O: Extend<I> + Default + Clone+ Send + 'static, | ||
{ | ||
type In = I; | ||
|
||
type Out = O; | ||
|
||
#[inline] | ||
fn process(&mut self, el: Self::In) { | ||
self.vec.push(el); | ||
self.collection.extend(std::iter::once(el)); | ||
} | ||
|
||
#[inline] | ||
fn output(self) -> Self::Out { | ||
(self.f)(self.vec) | ||
self.collection | ||
} | ||
} | ||
|
||
impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<Key, Out, OperatorChain, Out, WindowDescr> | ||
impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr> | ||
where | ||
WindowDescr: WindowDescription, | ||
OperatorChain: Operator<KeyValue<Key, Out>> + 'static, | ||
WindowDescr: WindowDescription<Out>, | ||
OperatorChain: Operator<Out = (Key, Out)> + 'static, | ||
Key: DataKey, | ||
Out: Data + Ord, | ||
{ | ||
/// Prefer other aggregators if possible as they don't save all elements | ||
pub fn map<NewOut: Data, F: Fn(Vec<Out>) -> NewOut + Send + Clone + 'static>( | ||
pub fn collect_to<C: Extend<Out> + Default + Clone + Send + 'static>( | ||
self, | ||
f: F, | ||
) -> KeyedStream<Key, NewOut, impl Operator<KeyValue<Key, NewOut>>> { | ||
let acc = CollectVec::<Out, NewOut, _> { | ||
vec: Default::default(), | ||
f, | ||
_o: PhantomData, | ||
) -> KeyedStream<impl Operator<Out = (Key, C)>> { | ||
let acc = CollectTo::<Out, C> { | ||
collection: Default::default(), | ||
_i: PhantomData, | ||
}; | ||
self.add_window_operator("WindowMap", acc) | ||
self.add_window_operator("WindowCollect", acc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters