Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix for CMS / REVIEW ONLY / DON'T MERGE #141

Merged
merged 1 commit into from

2 participants

@johnynek
Collaborator

No description provided.

@wlue

Ship it!

@johnynek johnynek merged commit 6d82ed8 into master
@caniszczyk caniszczyk deleted the hotfix/0.1.11 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @johnynek

    Hotfix for CMS

    johnynek authored
This page is out of date. Refresh to see the latest.
View
2  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?
View
11 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(_) }))
}
}
View
7 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 {
View
2  version.sbt
@@ -1,2 +1,2 @@
-version in ThisBuild := "0.1.10"
+version in ThisBuild := "0.1.11"
Something went wrong with that request. Please try again.