@libp2p/utils
Advanced tools
Comparing version 6.4.0 to 6.5.0-34b3c14b8
// 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'; | ||
const LN2_SQUARED = Math.LN2 * Math.LN2; | ||
@@ -30,3 +30,3 @@ export class BloomFilter { | ||
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; | ||
@@ -46,3 +46,3 @@ this.setbit(bit); | ||
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; | ||
@@ -49,0 +49,0 @@ const isSet = this.getbit(bit); |
@@ -5,5 +5,4 @@ export interface Hash { | ||
} | ||
export declare const murmur3: Hash; | ||
export declare const fnv1a: Hash; | ||
export declare function numberToBuffer(num: bigint | number): Uint8Array; | ||
//# sourceMappingURL=hashes.d.ts.map |
import fnv1aHash from '@sindresorhus/fnv1a'; | ||
import mur from 'murmurhash3js-revisited'; | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'; | ||
export const murmur3 = { | ||
hash: (input, seed) => { | ||
return mur.x86.hash32(input, seed); | ||
}, | ||
hashV: (input, seed) => { | ||
return numberToBuffer(murmur3.hash(input, seed)); | ||
} | ||
}; | ||
export const fnv1a = { | ||
@@ -13,0 +4,0 @@ hash: (input) => { |
import type { AbortOptions } from '@libp2p/interface'; | ||
export interface RepeatingTask { | ||
/** | ||
* Update the interval after which the next iteration of the task will run. | ||
* | ||
* This is useful if, for example, you want to retry a task with a short rest | ||
* duration until it succeeds, then periodically after that. | ||
* | ||
* This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setInterval(ms: number): void; | ||
/** | ||
* Update the amount of time a task will run before the passed abort signal | ||
* will fire. | ||
* | ||
* * This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setTimeout(ms: number): void; | ||
/** | ||
* Start the task running | ||
*/ | ||
start(): void; | ||
/** | ||
* Stop the task running | ||
*/ | ||
stop(): void; | ||
@@ -14,2 +38,4 @@ } | ||
* Whether to schedule the task to run immediately | ||
* | ||
* @default false | ||
*/ | ||
@@ -16,0 +42,0 @@ runImmediately?: boolean; |
@@ -30,2 +30,16 @@ import { setMaxListeners } from '@libp2p/interface'; | ||
return { | ||
setInterval: (ms) => { | ||
interval = ms; | ||
// maybe reschedule | ||
if (timeout != null) { | ||
clearTimeout(timeout); | ||
timeout = setTimeout(runTask, interval); | ||
} | ||
}, | ||
setTimeout: (ms) => { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
options.timeout = ms; | ||
}, | ||
start: () => { | ||
@@ -32,0 +46,0 @@ if (started) { |
{ | ||
"name": "@libp2p/utils", | ||
"version": "6.4.0", | ||
"version": "6.5.0-34b3c14b8", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -184,8 +184,7 @@ "license": "Apache-2.0 OR MIT", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "^5.0.10", | ||
"@libp2p/interface": "^2.4.1", | ||
"@libp2p/logger": "^5.1.7", | ||
"@libp2p/crypto": "5.0.10-34b3c14b8", | ||
"@libp2p/interface": "2.4.1-34b3c14b8", | ||
"@libp2p/logger": "5.1.7-34b3c14b8", | ||
"@multiformats/multiaddr": "^12.3.3", | ||
"@sindresorhus/fnv1a": "^3.1.0", | ||
"@types/murmurhash3js-revisited": "^3.0.3", | ||
"any-signal": "^4.1.1", | ||
@@ -199,3 +198,2 @@ "delay": "^6.0.0", | ||
"it-stream-types": "^2.0.2", | ||
"murmurhash3js-revisited": "^3.0.0", | ||
"netmask": "^2.0.2", | ||
@@ -209,3 +207,3 @@ "p-defer": "^4.0.1", | ||
"devDependencies": { | ||
"@libp2p/peer-id": "^5.0.11", | ||
"@libp2p/peer-id": "5.0.11-34b3c14b8", | ||
"@types/netmask": "^2.0.5", | ||
@@ -212,0 +210,0 @@ "aegir": "^45.0.5", |
// 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' | ||
@@ -42,3 +42,3 @@ | ||
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 | ||
@@ -61,3 +61,3 @@ | ||
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 | ||
@@ -64,0 +64,0 @@ |
import fnv1aHash from '@sindresorhus/fnv1a' | ||
import mur from 'murmurhash3js-revisited' | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
@@ -10,11 +9,2 @@ | ||
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 = { | ||
@@ -21,0 +11,0 @@ hash: (input) => { |
@@ -6,3 +6,30 @@ import { setMaxListeners } from '@libp2p/interface' | ||
export interface RepeatingTask { | ||
/** | ||
* Update the interval after which the next iteration of the task will run. | ||
* | ||
* This is useful if, for example, you want to retry a task with a short rest | ||
* duration until it succeeds, then periodically after that. | ||
* | ||
* This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setInterval(ms: number): void | ||
/** | ||
* Update the amount of time a task will run before the passed abort signal | ||
* will fire. | ||
* | ||
* * This only affects the next iteration of the task, if it is currently | ||
* running, that run will not be interrupted. | ||
*/ | ||
setTimeout(ms: number): void | ||
/** | ||
* Start the task running | ||
*/ | ||
start(): void | ||
/** | ||
* Stop the task running | ||
*/ | ||
stop(): void | ||
@@ -20,2 +47,4 @@ } | ||
* Whether to schedule the task to run immediately | ||
* | ||
* @default false | ||
*/ | ||
@@ -59,2 +88,18 @@ runImmediately?: boolean | ||
return { | ||
setInterval: (ms) => { | ||
interval = ms | ||
// maybe reschedule | ||
if (timeout != null) { | ||
clearTimeout(timeout) | ||
timeout = setTimeout(runTask, interval) | ||
} | ||
}, | ||
setTimeout: (ms) => { | ||
if (options == null) { | ||
options = {} | ||
} | ||
options.timeout = ms | ||
}, | ||
start: () => { | ||
@@ -61,0 +106,0 @@ if (started) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
21
280333
198
5344
1
+ Added@libp2p/crypto@5.0.10-34b3c14b8(transitive)
+ Added@libp2p/interface@2.4.1-34b3c14b8(transitive)
+ Added@libp2p/logger@5.1.7-34b3c14b8(transitive)
- Removedmurmurhash3js-revisited@^3.0.0
- Removed@libp2p/crypto@5.0.11(transitive)
- Removed@libp2p/interface@2.5.0(transitive)
- Removed@libp2p/logger@5.1.8(transitive)
- Removed@types/murmurhash3js-revisited@3.0.3(transitive)
- Removedmurmurhash3js-revisited@3.0.0(transitive)