Fix initial buffer size calculation.
This commit is contained in:
parent
9fbfcd2001
commit
98745832e8
|
@ -5,12 +5,13 @@
|
||||||
|
|
||||||
var typedArrays = typeof ArrayBuffer !== "undefined";
|
var typedArrays = typeof ArrayBuffer !== "undefined";
|
||||||
|
|
||||||
|
// Creates a new bloom filter with *m* bits and *k* hashing functions.
|
||||||
function BloomFilter(m, k) {
|
function BloomFilter(m, k) {
|
||||||
this.m = m;
|
this.m = m;
|
||||||
this.k = k;
|
this.k = k;
|
||||||
var n = Math.ceil(m / k);
|
var n = Math.ceil(m / 32);
|
||||||
if (typedArrays) {
|
if (typedArrays) {
|
||||||
var buffer = new ArrayBuffer(4 * n),
|
var buffer = new ArrayBuffer(32 * n),
|
||||||
kbytes = 1 << Math.ceil(Math.log(Math.ceil(Math.log(m) / Math.LN2 / 8)) / Math.LN2),
|
kbytes = 1 << Math.ceil(Math.log(Math.ceil(Math.log(m) / Math.LN2 / 8)) / Math.LN2),
|
||||||
array = kbytes === 1 ? Uint8Array : kbytes === 2 ? Uint16Array : Uint32Array,
|
array = kbytes === 1 ? Uint8Array : kbytes === 2 ? Uint16Array : Uint32Array,
|
||||||
kbuffer = new ArrayBuffer(kbytes * k);
|
kbuffer = new ArrayBuffer(kbytes * k);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bloomfilter",
|
"name": "bloomfilter",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"description": "Fast bloom filter in JavaScript.",
|
"description": "Fast bloom filter in JavaScript.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bloom filter",
|
"bloom filter",
|
||||||
|
|
Loading…
Reference in New Issue