Skip to content

Commit

Permalink
autoformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleSucher committed Apr 14, 2015
1 parent 59c280c commit 6efc590
Showing 1 changed file with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,55 @@ limitations under the License.

package com.twitter.algebird

case class HLLSeries(bits: Int, rows: Vector[Map[Int,Long]]) {
case class HLLSeries(bits: Int, rows: Vector[Map[Int, Long]]) {
def since(threshold: Long) =
HLLSeries(
bits,
rows.map{_.filter{case (j, ts) => ts >= threshold}})
rows.map{ _.filter{ case (j, ts) => ts >= threshold } })

def toHLL : HLL =
if(rows.isEmpty)
def toHLL: HLL =
if (rows.isEmpty)
SparseHLL(bits, Map())
else
rows.zipWithIndex.map{ case (map, i) =>
SparseHLL(bits, map.mapValues{ts => Max((i+1).toByte)}) : HLL
}.reduce{_ + _}
rows.zipWithIndex.map{
case (map, i) =>
SparseHLL(bits, map.mapValues{ ts => Max((i + 1).toByte) }): HLL
}.reduce{ _ + _ }
}

class HyperLogLogSeriesMonoid(val bits : Int) extends Monoid[HLLSeries] {
class HyperLogLogSeriesMonoid(val bits: Int) extends Monoid[HLLSeries] {
import HyperLogLog._

val zero = HLLSeries(bits, Vector())

def create(example : Array[Byte], timestamp: Long) : HLLSeries = {
def create(example: Array[Byte], timestamp: Long): HLLSeries = {
val hashed = hash(example)
val (j,rhow) = jRhoW(hashed, bits)
val (j, rhow) = jRhoW(hashed, bits)

val vector = Vector.fill(rhow-1){Map[Int,Long]()} ++ Vector(Map(j -> timestamp))
val vector = Vector.fill(rhow - 1){ Map[Int, Long]() } ++ Vector(Map(j -> timestamp))
HLLSeries(bits, vector)
}

def plus(left: HLLSeries, right: HLLSeries) : HLLSeries = {
if(left.rows.size > right.rows.size)
plus(right, left)
else {
val zipped = left.rows.zip(right.rows).map{case (l, r) =>
combine(l, r)
}
HLLSeries(
bits,
zipped ++ right.rows.slice(left.rows.size, right.rows.size))
def plus(left: HLLSeries, right: HLLSeries): HLLSeries = {
if (left.rows.size > right.rows.size)
plus(right, left)
else {
val zipped = left.rows.zip(right.rows).map{
case (l, r) =>
combine(l, r)
}
HLLSeries(
bits,
zipped ++ right.rows.slice(left.rows.size, right.rows.size))
}
}

private def combine(left: Map[Int,Long], right: Map[Int,Long]) : Map[Int,Long]= {
if(left.size > right.size)
combine(right, left)
private def combine(left: Map[Int, Long], right: Map[Int, Long]): Map[Int, Long] = {
if (left.size > right.size)
combine(right, left)
else {
right ++
left.map{case (k,v) => k -> (right.getOrElse(k, 0L).max(v))}
right ++
left.map{ case (k, v) => k -> (right.getOrElse(k, 0L).max(v)) }
}
}
}

0 comments on commit 6efc590

Please sign in to comment.