noir_compute/operator/window/aggr/
count.rs

1use super::super::*;
2use crate::operator::{Data, DataKey, Operator};
3use crate::stream::{KeyedStream, WindowedStream};
4
5#[derive(Clone)]
6pub(crate) struct Count<T>(usize, PhantomData<T>);
7
8impl<T: Data> WindowAccumulator for Count<T> {
9    type In = T;
10    type Out = usize;
11
12    #[inline]
13    fn process(&mut self, _: Self::In) {
14        self.0 += 1;
15    }
16
17    #[inline]
18    fn output(self) -> Self::Out {
19        self.0
20    }
21}
22
23impl<Key, Out, WindowDescr, OperatorChain> WindowedStream<OperatorChain, Out, WindowDescr>
24where
25    WindowDescr: WindowDescription<Out>,
26    OperatorChain: Operator<Out = (Key, Out)> + 'static,
27    Key: DataKey,
28    Out: Data,
29{
30    pub fn count(self) -> KeyedStream<impl Operator<Out = (Key, usize)>> {
31        let acc = Count(0, PhantomData);
32        self.add_window_operator("WindowCount", acc)
33    }
34}