-
Notifications
You must be signed in to change notification settings - Fork 26
/
count.rs
45 lines (39 loc) · 844 Bytes
/
count.rs
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
36
37
38
39
40
41
42
43
44
45
use derive_new::new;
use serde::{Deserialize, Serialize};
use super::{
folder_par_sink, FolderSync, FolderSyncReducer, ParallelPipe, ParallelSink, SumFolder
};
#[derive(new)]
#[must_use]
pub struct Count<P> {
pipe: P,
}
impl_par_dist! {
impl<P: ParallelPipe<Item>, Item> ParallelSink<Item> for Count<P> {
folder_par_sink!(
CountFolder,
SumFolder<usize>,
self,
CountFolder::new(),
SumFolder::new()
);
}
}
#[derive(Clone, Serialize, Deserialize, new)]
pub struct CountFolder;
impl<Item> FolderSync<Item> for CountFolder {
type State = usize;
type Done = Self::State;
#[inline(always)]
fn zero(&mut self) -> Self::State {
0
}
#[inline(always)]
fn push(&mut self, state: &mut Self::State, _item: Item) {
*state += 1;
}
#[inline(always)]
fn done(&mut self, state: Self::State) -> Self::Done {
state
}
}