@aggregion/binary-filter
v0.2.2
Published
Small package for compact store numbers in bit mask, calculate count of unique numbers
Downloads
14
Keywords
Readme
JS Binary Filter
Small package for compact store numbers in bit mask, calculate count of unique numbers
Install
npm i @aggregion/binary-filter
Usage
Binary filter add entries:
import {BinaryFilter} from '@aggregion/binary-filter'
const filter = new BinaryFilter(10000);
filter.add(1);
filter.add(12);
filter.add(20);
filter.add(1);
filter.has(1) // true
filter.has(5) // false
filter.length // 3
Create from list
const filter = BinaryFilter.from([1,2,3]);
Union and intersections
const filter1 = BinaryFilter.from([1,2,3]);
const filter2 = BinaryFilter.from([2,3,5]);
const union = filter1.union(filter2); // new filter, that contains 1,2,3,5
const intersection = filter2.intersect(filter2); // new filter, that contains 2,3