@@ -111,12 +111,22 @@ class CountMinSketchMonoid(eps : Double, delta : Double, seed : Int,
111
111
}
112
112
113
113
object CMS {
114
- def monoid (eps : Double , delta : Double , seed : Int , heavyHittersPct : Double = 0.01 ) =
114
+ def monoid (eps : Double , delta : Double , seed : Int , heavyHittersPct : Double = 0.01 ): CountMinSketchMonoid =
115
115
new CountMinSketchMonoid (eps, delta, seed, heavyHittersPct)
116
116
117
- def monoid (depth : Int , width : Int , seed : Int , heavyHittersPct : Double ) =
117
+ def monoid (depth : Int , width : Int , seed : Int , heavyHittersPct : Double ): CountMinSketchMonoid =
118
118
new CountMinSketchMonoid (CMS .eps(width), CMS .delta(depth), seed, heavyHittersPct)
119
119
120
+ def aggregator (eps : Double , delta : Double , seed : Int , heavyHittersPct : Double = 0.01 ): CountMinSketchAggregator = {
121
+ val monoid = new CountMinSketchMonoid (eps, delta, seed, heavyHittersPct)
122
+ new CountMinSketchAggregator (monoid)
123
+ }
124
+
125
+ def aggregator (depth : Int , width : Int , seed : Int , heavyHittersPct : Double ): CountMinSketchAggregator = {
126
+ val monoid = new CountMinSketchMonoid (CMS .eps(width), CMS .delta(depth), seed, heavyHittersPct)
127
+ new CountMinSketchAggregator (monoid)
128
+ }
129
+
120
130
/**
121
131
* Functions to translate between (eps, delta) and (depth, width). The translation is:
122
132
* depth = ceil(ln 1/delta)
@@ -453,3 +463,14 @@ case class HeavyHitter(item : Long, count : Long)
453
463
object HeavyHitter {
454
464
val ordering = Ordering .by { hh : HeavyHitter => (hh.count, hh.item) }
455
465
}
466
+
467
+ /**
468
+ * An Aggregator for the CountMinSketch.
469
+ * Can be created using CMS.aggregator
470
+ */
471
+ case class CountMinSketchAggregator (cmsMonoid : CountMinSketchMonoid ) extends MonoidAggregator [Long , CMS , CMS ] {
472
+ val monoid = cmsMonoid
473
+
474
+ def prepare (value : Long ) = monoid.create(value)
475
+ def present (cms : CMS ) = cms
476
+ }
0 commit comments