in algebird-core/src/main/scala/com/twitter/algebird/HyperLogLog.scala [404:431]
override def +(other: HLL): HLL =
other match {
case sparse @ SparseHLL(_, oMaxRhow) =>
assert(sparse.size == size, "Incompatible HLL size: " + sparse.size + " != " + size)
val allMaxRhow = Monoid.plus(maxRhow, oMaxRhow)
if (allMaxRhow.size * 16 <= size) {
SparseHLL(bits, allMaxRhow)
} else {
DenseHLL(bits, sparseMapToArray(allMaxRhow))
}
case DenseHLL(bits, oldV) =>
assert(oldV.size == size, "Incompatible HLL size: " + oldV.size + " != " + size)
val newContents: Array[Byte] = oldV.array.clone
val iter: Iterator[(Int, Max[Byte])] = maxRhow.iterator
while (iter.hasNext) {
val (idx, _) = iter.next()
val existing: Byte = newContents(idx)
val other: Byte = maxRhow(idx).get
if (other > existing)
newContents.update(idx, other)
}
DenseHLL(bits, Bytes(newContents))
}