public void HllPlusPlusBigValuesMergeTest() { // Bigger values (dense representation) HyperLogLog hll2 = new HyperLogLogPlusPlus(PRECISION_DEFAULT, SPARSE_PRECISION_DEFAULT); int i; for (i = 0; i < 150000; ++i) hll1.Add(i); for (i = 100000; i < 300000; ++i) hll2.Add(i); Assert.IsTrue(hll1.Merge(hll2), "Merge should alter some registers and return true"); TestsHelper.AssertRelativeError(300000UL, hll1.Cardinality); }
public void HllPlusPlusPrecisionTest() { const ulong expected = 10000; byte[] testPrecisions = new byte[] { 4, 12, 16 }; byte[] testSparsePrecisions = new byte[] { 18, 20, 24, 25, 28, 32, 46, 52, 63 }; foreach (byte p in testPrecisions) { foreach (byte sp in testSparsePrecisions) { HyperLogLog hll = new HyperLogLogPlusPlus(p, sp); for (ulong i = 0; i < expected; ++i) hll.Add(i); TestsHelper.AssertRelativeError(expected, hll.Cardinality); } } }
public void HllPlusPlusSmallValuesMergeTest() { HyperLogLog hll2 = new HyperLogLogPlusPlus(PRECISION_DEFAULT, SPARSE_PRECISION_DEFAULT); // Small values (sparse representation) hll1.Add(1); hll1.Add(2); hll1.Add(3); hll1.Add(4); hll1.Add(4); hll2.Add(3); hll2.Add(3); hll2.Add(4); hll2.Add(5); hll2.Add(6); hll2.Add(7); hll2.Add(7); Assert.IsTrue(hll1.Merge(hll2), "Merge should alter some registers and return true"); Assert.AreEqual(7UL, hll1.Cardinality, "Cardinality after merge should be up-to-date"); }
public void HllPlusPlusDifferentSparsePrecisionErrorTest() { HyperLogLog hll2 = new HyperLogLogPlusPlus(PRECISION_DEFAULT, 30); hll1.Merge(hll2); }
public void HllPlusPlusDifferentPrecisionsErrorTest() { HyperLogLog hll2 = new HyperLogLogPlusPlus(10, 20); hll1.Merge(hll2); }
public void HllPlusPlusDifferentPrecisionErrorTest() { HyperLogLog hll2 = new HyperLogLogPlusPlus(12, SPARSE_PRECISION_DEFAULT); hll1.Merge(hll2); }
private bool Merge(HyperLogLogPlusPlus hll) { bool modified = false; if (IsInSparseRepresentation) { foreach (int encodedValue in hll.SparseSet) if (SparseSet.Add(encodedValue)) modified = true; if (SparseSet.Count > SparseRepresentationThreshold) ToNormalRepresentation(); } else { for (int i = 0; i < hll.Registers.Count(); ++i) if (UpdateIfGreater(ref Registers[i], hll.Registers[i])) modified = true; } return modified; }