Skip to content

Commit

Permalink
Merge pull request twitter#274 from twitter/jco/261
Browse files Browse the repository at this point in the history
Remove extends function from algebird
  • Loading branch information
jcoveney committed Feb 25, 2014
2 parents c99e8e1 + 41ead3c commit faa2a25
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object Aggregator extends java.io.Serializable {
}
}

trait Aggregator[-A,B,+C] extends Function1[TraversableOnce[A], C] with java.io.Serializable { self =>
trait Aggregator[-A,B,+C] extends java.io.Serializable { self =>
def prepare(input : A) : B
def reduce(l : B, r : B) : B
def present(reduction : B) : C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ object CMSInstance {
*
* h(x) = [a * x + b (mod p)] (mod m)
*/
case class CMSHash(a : Int, b : Int, width : Int) extends Function1[Long, Int] {
case class CMSHash(a : Int, b : Int, width : Int) {

val PRIME_MODULUS = (1L << 31) - 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.twitter.algebird
* TODO remove T => Boolean. it ruins toString and doesn't help anything
* https://github.com/twitter/algebird/issues/261
*/
sealed trait Interval[T] extends (T => Boolean) with java.io.Serializable {
sealed trait Interval[T] extends java.io.Serializable {
def contains(t: T): Boolean

def intersect(that: Interval[T]): Interval[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ object Metric {
}

@implicitNotFound(msg = "Cannot find Metric type class for ${V}")
trait Metric[@specialized(Int,Long,Float,Double) -V] extends Function2[V, V, Double] with java.io.Serializable {
trait Metric[@specialized(Int,Long,Float,Double) -V] extends java.io.Serializable {
def apply(v1: V, v2: V): Double
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import scala.collection.breakOut
* Hashes an arbitrary key type to one that the Sketch Map can use.
*/
case class SketchMapHash[K](hasher: CMSHash, seed: Int)
(implicit serialization: K => Array[Byte])
extends Function1[K, Int] {
(implicit serialization: K => Array[Byte]) {
def apply(obj: K): Int = {
val (first, second) = MurmurHash128(seed)(serialization(obj))
hasher(first ^ second)
Expand Down Expand Up @@ -121,7 +120,8 @@ case class SketchMapParams[K](seed: Int, eps: Double, delta: Double, heavyHitter
val numHashes = depth
val numCounters = width
(0 to (numHashes - 1)).map { _ =>
SketchMapHash(CMSHash(r.nextInt, 0, numCounters), seed)(serialization)
val smhash: SketchMapHash[K] = SketchMapHash(CMSHash(r.nextInt, 0, numCounters), seed)(serialization)
new (K => Int) { override def apply(k: K) = smhash(k) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object SummingQueue {
}

class SummingQueue[V] private (capacity: Int)(override implicit val semigroup: Semigroup[V])
extends (V => Option[V]) with StatefulSummer[V] {
extends StatefulSummer[V] {

private val queueOption: Option[ArrayBlockingQueue[V]] =
if (capacity > 0) Some(new ArrayBlockingQueue[V](capacity, true)) else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ object BloomFilterLaws extends Properties("BloomFilter") {

object BFHashIndices extends Properties("BFHash") {
import org.scalacheck.Prop.forAll

val NUM_HASHES = 10
val WIDTH = 4752800

val SEED = 1

implicit val bfHash: Arbitrary[BFHash] =
Expand All @@ -39,13 +39,13 @@ object BFHashIndices extends Properties("BFHash") {
width <- choose(100, 5000000)
} yield BFHash(hashes, width, SEED)
}
property("Indices are non negative") = forAll{ (hash: BFHash, v: Long) => hash.apply(v.toString).forall(_ >= 0) }

property("Indices are non negative") = forAll{ (hash: BFHash, v: Long) => hash.apply(v.toString).forall(_ >= 0) }

/**
* This is the version of the BFHash as of before the "negative values fix"
* This is the version of the BFHash as of before the "negative values fix"
*/
case class NegativeBFHash(numHashes: Int, width: Int, seed: Long = 0L) extends Function1[String, Iterable[Int]]{
case class NegativeBFHash(numHashes: Int, width: Int, seed: Long = 0L) {
val size = numHashes

def apply(s: String) = nextHash(s.getBytes, numHashes)
Expand All @@ -72,7 +72,7 @@ object BFHashIndices extends Properties("BFHash") {
}
}
}

implicit val pairOfHashes: Arbitrary[(BFHash, NegativeBFHash)] =
Arbitrary {
for {
Expand All @@ -81,7 +81,7 @@ object BFHashIndices extends Properties("BFHash") {
} yield (BFHash(hashes, width, SEED), NegativeBFHash(hashes, width, SEED))
}

property("Indices of the two versions of BFHashes are the same, unless the first one contains negative index") =
property("Indices of the two versions of BFHashes are the same, unless the first one contains negative index") =
forAll{
(pair: (BFHash, NegativeBFHash), v: Long) =>
val s = v.toString
Expand Down Expand Up @@ -187,7 +187,7 @@ class BloomFilterTest extends Specification {
}

/**
* this test failed before the fix for https://github.com/twitter/algebird/issues/229
* this test failed before the fix for https://github.com/twitter/algebird/issues/229
*/
"not have negative hash values" in {
val NUM_HASHES = 2
Expand Down

0 comments on commit faa2a25

Please sign in to comment.