From df1d937f51e1c7906741ef823e2489d8b291dde5 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Sun, 20 Feb 2022 18:37:23 +0100 Subject: [PATCH] count: add generic `count_core` method This follows the pattern of `distinct_core` to allow counting a collection but use a different diff type than `isize`. Signed-off-by: Petros Angelatos --- src/operators/reduce.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/operators/reduce.rs b/src/operators/reduce.rs index 135128efe..f8d9edeb1 100644 --- a/src/operators/reduce.rs +++ b/src/operators/reduce.rs @@ -210,16 +210,25 @@ pub trait Count where G::Timestamp: Lattice+Ord /// }); /// } /// ``` - fn count(&self) -> Collection; + fn count(&self) -> Collection { + self.count_core() + } + + /// Count for general integer differences. + /// + /// This method allows `count` to produce collections whose difference + /// type is something other than an `isize` integer, for example perhaps an + /// `i32`. + fn count_core>(&self) -> Collection; } impl Count for Collection where G::Timestamp: Lattice+Ord, { - fn count(&self) -> Collection { + fn count_core>(&self) -> Collection { self.arrange_by_self_named("Arrange: Count") - .count() + .count_core() } } @@ -230,8 +239,8 @@ where T1::Batch: BatchReader, T1::Cursor: Cursor, { - fn count(&self) -> Collection { - self.reduce_abelian::<_,DefaultValTrace<_,_,_,_>>("Count", |_k,s,t| t.push((s[0].1.clone(), 1))) + fn count_core>(&self) -> Collection { + self.reduce_abelian::<_,DefaultValTrace<_,_,_,_>>("Count", |_k,s,t| t.push((s[0].1.clone(), R2::from(1i8)))) .as_collection(|k,c| (k.clone(), c.clone())) } }