Created
August 24, 2020 10:19
-
-
Save subintp/e820e2a7b51090fe38d610e5820075db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twitter.algebird.{ | |
HLL, | |
HyperLogLog, | |
HyperLogLogAggregator, | |
HyperLogLogMonoid | |
} | |
object HLL extends App { | |
val hllMonoid = new HyperLogLogMonoid(bits = 4) | |
val agg = HyperLogLogAggregator.withErrorGeneric[String](0.01) | |
val data = List("hello", "world", "wowww") | |
val combinedHll: HLL = agg(data) | |
println(s"old size: ${combinedHll.estimatedSize}") | |
// HLL to bytes | |
val hbytes = HyperLogLog.toBytes(combinedHll) | |
// Bytes to HLL | |
val newHll = HyperLogLog.fromBytes(hbytes) | |
// combine HLLS | |
val sum = hllMonoid.sum(Seq(combinedHll, newHll)) | |
println(s"new size: ${newHll.estimatedSize}") | |
println(s"combined size: ${sum.estimatedSize}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment