1.0.4 • Published 7 years ago

hibitset-js v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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.

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago