Skip to content

Commit f862b65

Browse files
authored
count: add generic count_core method (#356)
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 <petrosagg@gmail.com>
1 parent e4caf61 commit f862b65

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/operators/reduce.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,25 @@ pub trait Count<G: Scope, K: Data, R: Semigroup> where G::Timestamp: Lattice+Ord
210210
/// });
211211
/// }
212212
/// ```
213-
fn count(&self) -> Collection<G, (K, R), isize>;
213+
fn count(&self) -> Collection<G, (K, R), isize> {
214+
self.count_core()
215+
}
216+
217+
/// Count for general integer differences.
218+
///
219+
/// This method allows `count` to produce collections whose difference
220+
/// type is something other than an `isize` integer, for example perhaps an
221+
/// `i32`.
222+
fn count_core<R2: Abelian + From<i8>>(&self) -> Collection<G, (K, R), R2>;
214223
}
215224

216225
impl<G: Scope, K: ExchangeData+Hashable, R: ExchangeData+Semigroup> Count<G, K, R> for Collection<G, K, R>
217226
where
218227
G::Timestamp: Lattice+Ord,
219228
{
220-
fn count(&self) -> Collection<G, (K, R), isize> {
229+
fn count_core<R2: Abelian + From<i8>>(&self) -> Collection<G, (K, R), R2> {
221230
self.arrange_by_self_named("Arrange: Count")
222-
.count()
231+
.count_core()
223232
}
224233
}
225234

@@ -230,8 +239,8 @@ where
230239
T1::Batch: BatchReader<K, (), G::Timestamp, R>,
231240
T1::Cursor: Cursor<K, (), G::Timestamp, R>,
232241
{
233-
fn count(&self) -> Collection<G, (K, R), isize> {
234-
self.reduce_abelian::<_,DefaultValTrace<_,_,_,_>>("Count", |_k,s,t| t.push((s[0].1.clone(), 1)))
242+
fn count_core<R2: Abelian + From<i8>>(&self) -> Collection<G, (K, R), R2> {
243+
self.reduce_abelian::<_,DefaultValTrace<_,_,_,_>>("Count", |_k,s,t| t.push((s[0].1.clone(), R2::from(1i8))))
235244
.as_collection(|k,c| (k.clone(), c.clone()))
236245
}
237246
}

0 commit comments

Comments
 (0)