Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
folkvir committed May 22, 2024
1 parent 4ca4a38 commit 8ac32f6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/hashing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { xxh3 } from '@node-rs/xxhash'
import { bigIntToNumber, getBigIntAbs, numberToHex } from './utils.js'
import { getBigIntAbs, numberToHex } from './utils.js'

import {
TwoHashes,
Expand Down Expand Up @@ -60,7 +60,11 @@ export default class Hashing {
const arr = []
const hashes = this.hashTwice(element, seed)
for (let i = 0; i < hashCount; i++) {
arr.push(Number(BigInt.asUintN(32, this.doubleHashing(i, hashes.first, hashes.second, size))))
arr.push(
Number(
BigInt.asUintN(32, this.doubleHashing(i, hashes.first, hashes.second, size)),
),
)
}
if (arr.length !== hashCount) {
throw new Error('Please report: wrong number of indexes')
Expand Down
6 changes: 5 additions & 1 deletion src/partitioned-bloom-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export default class PartitionedBloomFilter
* @param errorRate - The desired error rate
* @return A new PartitionedBloomFilter optimal for the given parameters
*/
public static create(size: number, errorRate: number, nbHashes?: number): PartitionedBloomFilter {
public static create(
size: number,
errorRate: number,
nbHashes?: number,
): PartitionedBloomFilter {
const L = nbHashes ? nbHashes : Math.ceil(Math.log2(1 / errorRate))
const M = (size * Math.abs(Math.log(errorRate))) / Math.LN2 ** 2
// the optimal loadfactor is 0.5 for maximized size
Expand Down
2 changes: 1 addition & 1 deletion tests/cuckoo-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ test('issue#(https://github.com/Callidon/bloom-filters/issues/9)', () => {

// false positive rate should stay under the desired one
let fp = 0
let round = 10000
const round = 10000
for (let i = 0; i < round; i++) {
elems.forEach(e => {
// should return false
Expand Down
3 changes: 2 additions & 1 deletion tests/scalable-bloom-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ test('should #has return correct values with added values', () => {
fp++
}
}
// the error rate is respected but it is still probabilities,
// the error rate is respected but it is still probabilities,
// with a higher number of lookups the test is green
// so we multiply by 10 to ensure the test pass
// and also check it is around the desired error rate
expect(fp / round).toBeLessThanOrEqual(10 * 2 * e) // compounded error probability is bounded by P <= 2 * P0
} catch (e) {
// eslint-disable-next-line no-console
console.log(s)
throw e
}
Expand Down

0 comments on commit 8ac32f6

Please sign in to comment.