@@ -268,18 +268,31 @@ public FuzzySet downsize(float targetMaxSaturation) {
268
268
}
269
269
270
270
public int getEstimatedUniqueValues () {
271
- return getEstimatedNumberUniqueValuesAllowingForCollisions (bloomSize , filter .cardinality ());
271
+ return getEstimatedNumberUniqueValuesAllowingForCollisions (
272
+ bloomSize , filter .cardinality (), hashCount );
272
273
}
273
274
274
- // Given a set size and a the number of set bits, produces an estimate of the number of unique
275
- // values recorded
275
+ /**
276
+ * Given a set size and the number of set bits, produces an estimate of the number of unique
277
+ * values recorded (assuming a single hash function is used)
278
+ */
276
279
public static int getEstimatedNumberUniqueValuesAllowingForCollisions (
277
280
int setSize , int numRecordedBits ) {
281
+ return getEstimatedNumberUniqueValuesAllowingForCollisions (setSize , numRecordedBits , 1 );
282
+ }
283
+
284
+ /**
285
+ * Given a set size, the number of set bits and hash function count, produces an estimate of the
286
+ * number of unique values recorded
287
+ */
288
+ public static int getEstimatedNumberUniqueValuesAllowingForCollisions (
289
+ int setSize , int numRecordedBits , int hashCount ) {
278
290
double setSizeAsDouble = setSize ;
279
291
double numRecordedBitsAsDouble = numRecordedBits ;
292
+ double hashCountAsDouble = hashCount ;
280
293
double saturation = numRecordedBitsAsDouble / setSizeAsDouble ;
281
294
double logInverseSaturation = Math .log (1 - saturation ) * -1 ;
282
- return (int ) (setSizeAsDouble * logInverseSaturation );
295
+ return (int ) (setSizeAsDouble * logInverseSaturation / hashCountAsDouble );
283
296
}
284
297
285
298
public float getTargetMaxSaturation () {
0 commit comments