diff --git a/README.md b/README.md index acf1f6147..cca5ce9a1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ For example, average, moving average, max/min, set analytics. ## Maven -Current version is `0.1.10`. groupid=`"com.twitter"` artifact=`"algebird-core_2.9.2"`. +Current version is `0.1.11`. groupid=`"com.twitter"` artifact=`"algebird-core_2.9.2"`. ## Questions > Why not use spire? diff --git a/algebird-core/src/main/scala/com/twitter/algebird/CountMinSketch.scala b/algebird-core/src/main/scala/com/twitter/algebird/CountMinSketch.scala index 35d5abe3b..c3299827a 100644 --- a/algebird-core/src/main/scala/com/twitter/algebird/CountMinSketch.scala +++ b/algebird-core/src/main/scala/com/twitter/algebird/CountMinSketch.scala @@ -377,6 +377,7 @@ case class CMSHash(a : Int, b : Int, width : Int) extends Function1[Long, Int] { /** * The 2-dimensional table of counters used in the Count-Min sketch. * Each row corresponds to a particular hash function. + * TODO: implement a dense matrix type, and use it here */ case class CMSCountsTable(counts : Vector[Vector[Long]]) { assert(depth > 0, "Table must have at least 1 row.") @@ -409,10 +410,14 @@ case class CMSCountsTable(counts : Vector[Vector[Long]]) { */ def ++(other : CMSCountsTable) : CMSCountsTable = { assert((depth, width) == (other.depth, other.width), "Tables must have the same dimensions.") - - (0 to (depth - 1)).zip(0 to (width - 1)).foldLeft(this) { - case (table, pos) => table + (pos, other.getCount(pos)) + val iil = Monoid.plus[IndexedSeq[IndexedSeq[Long]]](counts, other.counts) + def toVector[V](is: IndexedSeq[V]): Vector[V] = { + is match { + case v: Vector[V] => v + case _ => Vector(is: _*) + } } + CMSCountsTable(toVector(iil.map { toVector(_) })) } } diff --git a/algebird-test/src/test/scala/com/twitter/algebird/CountMinSketchTest.scala b/algebird-test/src/test/scala/com/twitter/algebird/CountMinSketchTest.scala index 1c94e758a..01f55d1ff 100644 --- a/algebird-test/src/test/scala/com/twitter/algebird/CountMinSketchTest.scala +++ b/algebird-test/src/test/scala/com/twitter/algebird/CountMinSketchTest.scala @@ -97,6 +97,13 @@ class CountMinSketchTest extends Specification { cms.frequency(0).estimate must be_==(0) cms.frequency(1).estimate must be_==(1) cms.frequency(2).estimate must be_==(2) + + val three = CMS_MONOID.create(Seq(1L, 1L, 1L)) + three.frequency(1L).estimate must be_==(3) + val four = CMS_MONOID.create(Seq(1L, 1L, 1L, 1L)) + four.frequency(1L).estimate must be_==(4) + val cms2 = CMS_MONOID.plus(four, three) + cms2.frequency(1L).estimate must be_==(7) } "estimate inner products" in { diff --git a/version.sbt b/version.sbt index 87913ece4..8acf1c589 100644 --- a/version.sbt +++ b/version.sbt @@ -1,2 +1,2 @@ -version in ThisBuild := "0.1.10" +version in ThisBuild := "0.1.11"