bloom: ensure min values.

This commit is contained in:
Christopher Jeffrey 2017-01-11 15:38:24 -08:00
parent 8c1002e1da
commit 40ff06f11f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -272,6 +272,7 @@ Bloom.fromRate = function fromRate(items, rate, update) {
assert(rate >= 0 && rate <= 1, '`rate` must be between 0.0 and 1.0.');
size = (-1 / LN2SQUARED * items * Math.log(rate)) | 0;
size = Math.max(8, size);
if (update !== -1)
size = Math.min(size, Bloom.MAX_BLOOM_FILTER_SIZE * 8);
@ -433,6 +434,7 @@ RollingFilter.prototype.fromRate = function fromRate(items, rate) {
items = ((size + 63) / 64 | 0) << 1;
items >>>= 0;
items = Math.max(1, items);
tweak = (Math.random() * 0x100000000) >>> 0;