Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
"@libp2p/logger": "^5.1.7",
"@multiformats/multiaddr": "^12.3.3",
"@sindresorhus/fnv1a": "^3.1.0",
"@types/murmurhash3js-revisited": "^3.0.3",
"any-signal": "^4.1.1",
"delay": "^6.0.0",
"get-iterator": "^2.0.1",
Expand All @@ -195,7 +194,6 @@
"it-pipe": "^3.0.1",
"it-pushable": "^3.2.3",
"it-stream-types": "^2.0.2",
"murmurhash3js-revisited": "^3.0.0",
"netmask": "^2.0.2",
"p-defer": "^4.0.1",
"race-event": "^1.3.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/utils/src/filters/bloom-filter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// ported from xxbloom - https://github.com/ceejbot/xxbloom/blob/master/LICENSE
import { randomBytes } from '@libp2p/crypto'
import mur from 'murmurhash3js-revisited'
import { Uint8ArrayList } from 'uint8arraylist'
import { alloc } from 'uint8arrays/alloc'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { fnv1a } from './hashes.js'
import type { Filter } from './index.js'

const LN2_SQUARED = Math.LN2 * Math.LN2
Expand Down Expand Up @@ -39,7 +39,7 @@ export class BloomFilter implements Filter {
}

for (let i = 0; i < this.seeds.length; i++) {
const hash = mur.x86.hash32(item, this.seeds[i])
const hash = fnv1a.hash(item, this.seeds[i])
const bit = hash % this.bits

this.setbit(bit)
Expand All @@ -57,7 +57,7 @@ export class BloomFilter implements Filter {
}

for (let i = 0; i < this.seeds.length; i++) {
const hash = mur.x86.hash32(item, this.seeds[i])
const hash = fnv1a.hash(item, this.seeds[i])
const bit = hash % this.bits

const isSet = this.getbit(bit)
Expand Down
10 changes: 0 additions & 10 deletions packages/utils/src/filters/hashes.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import fnv1aHash from '@sindresorhus/fnv1a'
import mur from 'murmurhash3js-revisited'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

export interface Hash {
hash(input: Uint8Array, seed: number): number
hashV(input: Uint8Array, seed: number): Uint8Array
}

export const murmur3: Hash = {
hash: (input, seed) => {
return mur.x86.hash32(input, seed)
},
hashV: (input, seed) => {
return numberToBuffer(murmur3.hash(input, seed))
}
}

export const fnv1a: Hash = {
hash: (input) => {
return Number(fnv1aHash(input, {
Expand Down
Loading