@Test public void testHLLDenseNoBitPackingHalfDistinct() throws IOException { HyperLogLog hll = HyperLogLog.builder().setEncoding(EncodingType.DENSE).enableBitPacking(false) .build(); Random rand = new Random(SEED); Set<Integer> hashset = new HashSet<>(); for (int i = 0; i < size; i++) { int val = rand.nextInt(size / 2); hll.addLong(val); hashset.add(val); } FileOutputStream fos = new FileOutputStream(testFile); DataOutputStream out = new DataOutputStream(fos); HyperLogLogUtils.serializeHLL(out, hll); double threshold = size > 40000 ? longRangeTolerance : shortRangeTolerance; double delta = threshold * hashset.size() / 100; FileInputStream fis = new FileInputStream(testFile); DataInputStream in = new DataInputStream(fis); HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in); assertEquals(hll, deserializedHLL); assertEquals(hll.toString(), deserializedHLL.toString()); assertEquals(hll.toStringExtended(), deserializedHLL.toStringExtended()); assertEquals(hll.hashCode(), deserializedHLL.hashCode()); assertEquals(hll.count(), deserializedHLL.count()); assertEquals(hashset.size(), hll.count(), delta); assertEquals(hashset.size(), deserializedHLL.count(), delta); } }
@Test public void testHLLSparseNoBitPackingHalfDistinct() throws IOException { HyperLogLog hll = HyperLogLog.builder().setEncoding(EncodingType.SPARSE) .enableBitPacking(false).build(); Random rand = new Random(SEED); Set<Integer> hashset = new HashSet<>(); for (int i = 0; i < size; i++) { int val = rand.nextInt(size / 2); hll.addLong(val); hashset.add(val); } FileOutputStream fos = new FileOutputStream(testFile); DataOutputStream out = new DataOutputStream(fos); HyperLogLogUtils.serializeHLL(out, hll); double threshold = size > 40000 ? longRangeTolerance : shortRangeTolerance; double delta = threshold * hashset.size() / 100; FileInputStream fis = new FileInputStream(testFile); DataInputStream in = new DataInputStream(fis); HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in); assertEquals(hll, deserializedHLL); assertEquals(hll.toString(), deserializedHLL.toString()); assertEquals(hll.toStringExtended(), deserializedHLL.toStringExtended()); assertEquals(hll.hashCode(), deserializedHLL.hashCode()); assertEquals(hll.count(), deserializedHLL.count()); assertEquals(hashset.size(), hll.count(), delta); assertEquals(hashset.size(), deserializedHLL.count(), delta); }
@Test public void testHLLSparseNoBitPacking() throws IOException { HyperLogLog hll = HyperLogLog.builder().setEncoding(EncodingType.SPARSE) .enableBitPacking(false).build(); Random rand = new Random(SEED); for (int i = 0; i < size; i++) { hll.addLong(rand.nextLong()); } FileOutputStream fos = new FileOutputStream(testFile); DataOutputStream out = new DataOutputStream(fos); HyperLogLogUtils.serializeHLL(out, hll); FileInputStream fis = new FileInputStream(testFile); DataInputStream in = new DataInputStream(fis); HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in); assertEquals(hll, deserializedHLL); assertEquals(hll.toString(), deserializedHLL.toString()); assertEquals(hll.toStringExtended(), deserializedHLL.toStringExtended()); assertEquals(hll.hashCode(), deserializedHLL.hashCode()); assertEquals(hll.count(), deserializedHLL.count()); }
.setEncoding(EncodingType.DENSE).enableBitPacking(false).build(); } else { result = HyperLogLog.builder().setNumRegisterIndexBits(p) .setEncoding(EncodingType.DENSE).enableBitPacking(true).build();
@Test public void testHLLDenseNoBitPacking() throws IOException { HyperLogLog hll = HyperLogLog.builder().setEncoding(EncodingType.DENSE).enableBitPacking(false) .build(); Random rand = new Random(SEED); for (int i = 0; i < size; i++) { hll.addLong(rand.nextLong()); } FileOutputStream fos = new FileOutputStream(testFile); DataOutputStream out = new DataOutputStream(fos); HyperLogLogUtils.serializeHLL(out, hll); FileInputStream fis = new FileInputStream(testFile); DataInputStream in = new DataInputStream(fis); HyperLogLog deserializedHLL = HyperLogLogUtils.deserializeHLL(in); assertEquals(hll, deserializedHLL); assertEquals(hll.toString(), deserializedHLL.toString()); assertEquals(hll.toStringExtended(), deserializedHLL.toStringExtended()); assertEquals(hll.hashCode(), deserializedHLL.hashCode()); assertEquals(hll.count(), deserializedHLL.count()); }