Skip to content

Commit bed55a5

Browse files
authored
Merge pull request #25 from xzeck/bug-fix/overflow-adjustment
Added overflow adjustment
2 parents cd46630 + 5fc638d commit bed55a5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<T: ToBytes, S: BuildHasher + Default + Clone> HyperLogLog<T, S> {
152152
mm if mm >= 128 => 0.7213 / (1.0 + 1.079 / (mm as f64)),
153153
_ => unreachable!("Bucket count m={} is unsupported", self.m),
154154
};
155-
let estimate = alpha * m * m * z;
155+
let mut estimate = alpha * m * m * z;
156156

157157
// Small-range (linear counting) correction: m * ln(m / V)
158158
if zero > 0.0 {
@@ -162,6 +162,10 @@ impl<T: ToBytes, S: BuildHasher + Default + Clone> HyperLogLog<T, S> {
162162
}
163163
}
164164

165+
if estimate > (1.0/30.0) * (2.0f64.powi(32)) {
166+
estimate = -2.0f64.powi(32) * (1.0 - (estimate / 2.0f64.powi(32))).ln();
167+
}
168+
165169
estimate.round() as u64
166170
}
167171

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let insertion_start = Instant::now();
88
let mut hashset: HashSet<i64> = HashSet::new();
99

10-
for i in -1_000_000i64..1_000_000 {
10+
for i in -1_000_000_00i64..1_000_000_00 {
1111
hll.insert(i);
1212
hashset.insert(i);
1313
}

0 commit comments

Comments
 (0)