You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.expect("Every BloomObject is expected to have at least one filter")
249
254
.seed()
250
255
}
256
+
/// Return the starting capacity used by the Bloom object. This capacity is held within the first filter
257
+
pubfnstarting_capacity(&self) -> i64{
258
+
self.filters
259
+
.first()
260
+
.expect("Every BloomObject is expected to have at least one filter")
261
+
.capacity()
262
+
}
251
263
252
264
/// Return the expansion of the bloom object.
253
265
pubfnexpansion(&self) -> u32{
@@ -319,7 +331,7 @@ impl BloomObject {
319
331
Some(new_capacity) => new_capacity,
320
332
None => {
321
333
// u32:max cannot be reached with 64MB memory usage limit per filter even with a high fp rate (e.g. 0.9).
322
-
returnErr(BloomError::MaxNumScalingFilters);
334
+
returnErr(BloomError::BadCapacity);
323
335
}
324
336
};
325
337
// Reject the request, if the operation will result in creation of a filter of size greater than what is allowed.
@@ -373,7 +385,7 @@ impl BloomObject {
373
385
) -> Result<f64,BloomError>{
374
386
match fp_rate * tightening_ratio.powi(num_filters){
375
387
x if x > f64::MIN_POSITIVE => Ok(x),
376
-
_ => Err(BloomError::MaxNumScalingFilters),
388
+
_ => Err(BloomError::FalsePositiveReachesZero),
377
389
}
378
390
}
379
391
@@ -463,42 +475,76 @@ impl BloomObject {
463
475
}
464
476
}
465
477
466
-
pubfncalculate_if_wanted_capacity_is_valid(
478
+
/// This method is called from two different bloom commands: BF.INFO and BF.INSERT. The functionality varies slightly on which command it
479
+
/// is called from. When called from BF.INFO, this method is used to find the maximum possible size that the bloom object could scale to
480
+
/// without throwing an error. When called from BF.INSERT, this method is used to determine if it is possible to reach the provided `validate_scale_to`.
481
+
///
482
+
/// # Arguments
483
+
///
484
+
/// * `capacity` - The size of the initial filter in the bloom object.
485
+
/// * `fp_rate` - the false positive rate for the bloom object
486
+
/// * `validate_scale_to` - the capacity we check to see if it can scale to. If this method is called from BF.INFO this is set as -1 as we
487
+
/// want to check the maximum size we could scale up till
488
+
/// * `tightening_ratio` - The tightening ratio of the object
489
+
/// * `expansion` - The expanison rate of the object
490
+
///
491
+
/// # Returns
492
+
/// * i64 - The maximum capacity that can be reached if called from BF.INFO. If called from BF.INSERT the size it reached when it became greater than `validate_scale_to`
493
+
/// * ValkeyError - Can return two different errors:
494
+
/// VALIDATE_SCALE_TO_EXCEEDS_MAX_SIZE: When scaling to the wanted capacity would go over the bloom object memory limit
495
+
/// VALIDATE_SCALE_TO_FALSE_POSITIVE_INVALID: When scaling to the wanted capacity would cause the false positive rate to reach 0
0 commit comments