0.3.6 • Published 4 years ago

cell-bitset v0.3.6

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Build Status Coverage Status Inline docs MIT license

Fast(est) & consistent JavaScript BitSet (AKA bitvector, bitarray, bitstring) implementation. Implemented as part of my upcoming(...loading...) cell game engine, but perfectly usable as a standalone lib.

Features

  • Fast!
  • Fully tested
  • Fully documented
  • Both bitset & bitvector like methods
  • Pascal methods respect immutability
  • Chaining
  • Lots of aliases
  • Lots of output options
  • ES6 binaries
  • Made with bits of love!

Installation

npm

npm install cell-bitset

Usage

const bs1 = BitSet.create() // default length is 32
    .set(7)
    .set(54) // the length of the underlying bitvector is automatically resized to 55
    .set(23);

const bs2 = BitSet.create(68) // create a bitvector with a specific size
    .add(7, 67, 23);

const bs3 = new BitSet([7, 54, 23]); // use an iterable to initialize the bitset.

bs1.union(bs2);

expect(bs1.toString()).to.eql('{7, 23, 54, 67}');
expect(bs1.toString(2)).to.eql('10000000000001000000000000000000000000000000100000000000000010000000'); // will output the bitstring
expect(bs1.length).to.eql(68); // The length of the underlying bitvector. The length of bs1 is automatically resized
expect(bs1.cardinality).to.eql(4); // i.e. the number of flipped bits

const bs4 = bs3.Union(bs2); // use Pascal case Union to output a new bitset and leave bs3 unchanged

expect(bs3.toString()).to.eql('{7, 23, 54}');
expect(bs4.toString()).to.eql('{7, 23, 54, 67}');

For more usage example see the unit tests.

0.3.6

4 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago