Skip to content

Hierarchical Bitset for efficient iteration and boolean operations on sparse data.

License

Notifications You must be signed in to change notification settings

Xerios/hibitset-js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

Hierarchical Bitset for efficient iteration and boolean operations on sparse data. This is a translation to js of the amazing hibitset.

Code Example

import * as B from "hibitset-js";
const set = new B.BitSet(0);
for(var i = 0; i < 1000; i += 1) {
    expect(set.add(i)).toBeFalsy();
    expect(set.add(i)).toBeTruthy();
}
for(var i = 0; i < 1000; i += 1) {
    expect(set.contains(i)).toBeTruthy();
}

const B.xor(set, B.zero(set.size()));

function iterate(a: B.HierarchicalBitset, callback: (value: object) => void) {
  const iterator = B.createIterator(a);
  while(true) {
    const { value, done } = iterator.next();
    if(done) {
      break;
    }
    callback(value);
  };
}

the first part is an excerpt from the tests. Then a boolean operation and the zero factory method are demonstrated. The iterate function showcases how to iterate over a BitSet. The iterate and createIterator functions are part of the library. The HierarchicalBitset type is an interface shared by all BitSets.

Motivation

Hierarchical Bitsets are extremely useful to iterate over sparse data structures.

Installation

checkout the project and

npm install && npm test

API Reference

Tests

jest --watch

License

MIT.

About

Hierarchical Bitset for efficient iteration and boolean operations on sparse data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 83.5%
  • JavaScript 16.5%