Bael 1010 hll (#2256)
* BAEL-1010 HLL article code * BAEL-1010 moved tolerated difference to a variable * Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-1010_hll # Conflicts: # libraries/pom.xml * BAEL-1010 clearer code
This commit is contained in:
parent
7df3f24350
commit
3718dfd0d1
|
@ -22,9 +22,9 @@ public class HLLUnitTest {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
hll.addRaw(hashedValue);
|
hll.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
|
@ -43,21 +43,22 @@ public class HLLUnitTest {
|
||||||
|
|
||||||
//when
|
//when
|
||||||
LongStream.range(0, numberOfElements).forEach(element -> {
|
LongStream.range(0, numberOfElements).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
firstHll.addRaw(hashedValue);
|
firstHll.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
|
LongStream.range(numberOfElements, numberOfElements * 2).forEach(element -> {
|
||||||
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
long hashedValue = hashFunction.newHasher().putLong(element).hash().asLong();
|
||||||
secondHLL.addRaw(hashedValue);
|
secondHLL.addRaw(hashedValue);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
firstHll.union(secondHLL);
|
firstHll.union(secondHLL);
|
||||||
long cardinality = firstHll.cardinality();
|
long cardinality = firstHll.cardinality();
|
||||||
assertThat(isSimilarTo(cardinality, numberOfElements * 2, toleratedDifference)).isTrue();
|
assertThat(isSimilarTo(cardinality, numberOfElements * 2,
|
||||||
|
toleratedDifference * 2)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSimilarTo(long cardinality, int numberOfElements, int maxToleratedDifference) {
|
private boolean isSimilarTo(long cardinality, int numberOfElements, int maxToleratedDifference) {
|
||||||
|
|
Loading…
Reference in New Issue