npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

binary-fuse-filter

v1.0.0

Published

JavaScript-TypeScript module implementing binary fuse 8 filter for BigInt

Downloads

3

Readme

binary-fuse-filter: JavaScript-TypeScript module implementing binary fuse 8 filter for BigInt

This is a partial port of the xorfilter: Go library implementing xor and binary fuse filters Please visit them if you need more information how such ADTs work.

General

From the original authors:

We are assuming that your set is made of 64-bit integers. If you have strings or other data structures, you need to hash them first to a 64-bit integer. It is not important to have a good hash function, but collision should be unlikely (~1/2^64). A few collisions are acceptable, but we expect that your initial set should have no duplicated entry.

The current JS-TS implementation has a false positive rate bellow 0.4% and a memory usage of 9 bits per entry for sizeable sets.

In the original Go version, you construct the filter, starting from a slice of 64-bit large integers. It returns an object of type BinaryFuse8. The 64-bit integers would typically be hash values of your objects.

In the JavaScript version we do:

const bff = require('binary-fuse-filter')

const keys = [
    509134857359967859n, 
    6960900220364064023n, 
    11597439857860732537n, 
    9784652298804248601n, 
    4886430609114338934n
]

const [ filter, err ] = bff.populateBinaryFuse8(keys)
if (err) { throw err } // alternatively you can catch the err

And the key container can be one of the following types.

type T = 
Array<bigint> | Array<number> | Array<number | bigint> | 
Uint32Array | BigUint64Array 

You can then query it as follows:

filter.contains(509134857359967859n) // true
filter.contains(12345) // false

extended API

The filter object has a few more methods:

filter.makeJSON() 
// => return filter as a JavaScript Object Notation (JSON) string

filter.takeJSON(json: string) 
// consume JavaScript Object Notation (JSON) string representing the filter

filter.reInit(keys: T) 
// populate the same filter variable with new keys

more

A basic 4-core Intel processor will generate, fill, and verify 1e6 random 64-bit keys in less than 2.5 seconds. Converting the same filter built on 1e6 entries with makeJSON() to a string and parsing back with takeJSON() takes around 100ms.

Assuming you have cloned the project, you can run the test in the root folder. It is done with Node.js' Test runner.

npm --test

The library has zero dependencies.

install

npm -i binary-fuse-filter