You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by pl...@apache.org on 2024/05/24 20:11:12 UTC

(datasketches-go) 01/01: [Go] Optimise HLL union merge (HLLtoHLL)

This is an automated email from the ASF dual-hosted git repository.

placave pushed a commit to branch hll-union-optim
in repository https://gitbox.apache.org/repos/asf/datasketches-go.git

commit 392504916661f0b500a399febeff52ac13af10c7
Author: Pierre Lacave <pi...@datadoghq.com>
AuthorDate: Fri May 24 22:10:56 2024 +0200

    [Go] Optimise HLL union merge (HLLtoHLL)
---
 hll/hll_sketch_test.go | 15 +++++++++++++++
 hll/union.go           |  8 ++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/hll/hll_sketch_test.go b/hll/hll_sketch_test.go
index bf38c45..b3ae50d 100644
--- a/hll/hll_sketch_test.go
+++ b/hll/hll_sketch_test.go
@@ -420,3 +420,18 @@ func TestHLL4RawStoredOldNibbleAndShiftedNewValueAuxToken(t *testing.T) {
 	err := hll.UpdateUInt64(29197004)
 	assert.NoError(t, err)
 }
+
+func BenchmarkHLLMerge(b *testing.B) {
+	hll1, err := NewHllSketch(11, TgtHllTypeHll8)
+	for i := uint64(0); i < 29197004; i++ {
+		err = hll1.UpdateUInt64(i)
+		assert.NoError(b, err)
+	}
+	u, _ := NewUnion(11)
+
+	b.Run("merge", func(b *testing.B) {
+		for i := 0; i < b.N; i++ {
+			u.UpdateSketch(hll1)
+		}
+	})
+}
diff --git a/hll/union.go b/hll/union.go
index c63b223..b06935f 100644
--- a/hll/union.go
+++ b/hll/union.go
@@ -377,10 +377,10 @@ func mergeHlltoHLLmode(src HllSketch, tgt HllSketch, srcLgK int, tgtLgK int) err
 		{
 			srcArr := src.(*hllSketchState).sketch.(*hll8ArrayImpl).hllByteArr
 			tgtArr := tgt.(*hllSketchState).sketch.(*hll8ArrayImpl).hllByteArr
-			for i := 0; i < srcK; i++ {
-				srcV := srcArr[i]
-				tgtV := tgtArr[i]
-				tgtArr[i] = max(srcV, tgtV)
+			for i, srcV := range srcArr {
+				if srcV > tgtArr[i] {
+					tgtArr[i] = srcV
+				}
 			}
 		}
 	case 8, 9: //!HLL_8, srcLgK=tgtLgK, src=heap, tgt=heap/mem


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org