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

bit-vec

v1.0.4

Published

Lightweight BitArray implementation written in javascript.

Downloads

19

Readme

bit-vec

Coverage Status npm version npm

A lightweight, performant and well documented BitArray/BitVector implementation written in javascript.

Installing

Via NPM: npm install bit-vec --save.

Getting Started

After installing

import BitVector from 'bit-vec';

const bitVec = new BitVector(8);

Example Usage:

import BitVector from 'bit-vec';

const bitVec = new BitVector(8);
bitVec.set(5, 1);
bitVec.test(5); // true
bitVec.flip(5);
bitVec.test(5); // false

// Chaining.
bitVec
  .set(5)
  .set(3)
  .set(1)
  .clearRange(0, 4)
  .test(3); // false

Condensed Documentation

Below is a condensed form of the documentation, each is a function that can be found on the BitVector object, called like so.

const bitVec = new BitVector(42);
bitVec.test(34); // false
bitVec.set(34, 1);
bitVec.test(34); // true

| Method | Parameters | Return | | ----------- | -------- | ------ | | .get(index) | index:Number | Number, 1 if set, 0 if not. | | .set(index) | index:Number | Returns this with the bit set. | | .test(index) | index:Number | Returns Boolean true if index is set, false otherwise . | | .clear(index) | index:Number | Returns this with cleared bit. | | .flip(index) | index:Number | Returns this with flipper bit. | | .count() | None | Returns Number number of indices currently set to 1. | | .setRange(begin, end, value = 1) | begin:Number, end:Number, value:Number | Returns this with bits set.| | .clearRange(begin, end) | begin:Number, end:Number | Returns this with bits cleared. | | .equals(bitVec) | bitVec:BitVector | Returns Boolean true if the two bit vectors are equal, false otherwise. | | .notEquals(bitVec) | bitVec:BitVector | Returns Boolean true if the two bit vectors are different, false otherwise. | | .or(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .xor(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .and(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .not() | None | Returns new BitVector object with the result of the operation. | | .invert() | None | Returns this with updated array. | | .orEqual(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .xorEqual(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .andEqual(bitVec) | bitVec:BitVector | Returns new BitVector object with the result of the operation.| | .notEqual() | None | Returns new BitVector object with the result of the operation. | | .isEmpty() | None |Returns Boolean true if the bit vector has no set bits, false otherwise. |

Full Documentation


get

bitVec.get(index)

Performs a get operation on the given index, retrieving the stored value (0 or 1).

Parameters
  • index -> Number for index: 0 <= index < bitVec.bits.
Returns

Number, 1 if set, 0 otherwise.

Example
bitVec.get(52); // 0

set

bitVec.set(index)

Performs a set operation on the given index, setting the value to either 0 or 1.

Parameters
  • index -> Number for index: 0 <= index < bitVec.bits.
  • value -> Number, 0 or 1, defaults to 1.
Returns

Returns BitVector for chaining with the bit set.

Example
bitVec.set(52); // BitVector

test

bitVec.test(index)

Tests whether the given index is set to 1.

Parameters
  • index -> Number for index: 0 <= index < bitVec.bits.
Returns

Returns Boolean true if index is set, false otherwise .

Example
bitVec.set(52, 1);
bitVec.test(52); // true

clear

bitVec.clear(index)

Clears the bit at the given index.

Parameters
  • index -> Number for index: 0 <= index < bitVec.bits.
Returns

Returns BitVector for chaining with the bit cleared.

Example
bitVec.set(52, 1);
bitVec.test(52); // true

flip

bitVec.flip(index)

Flips the bit at the given index.

Parameters
  • index -> Number for index: 0 <= index < bitVec.bits.
Returns

Returns BitVector for chaining with the bit cleared.

Example
bitVec.flip(52);

count

bitVec.count()

Counts the number of set bits in the bit vector.

Parameters
  • None
Returns

Returns Number number of indices currently set to 1.

Example
bitVec.count();

setRange

bitVec.setRange(begin, end, value = 1)

Sets a range of bits from begin to end.

Parameters
  • begin -> Number for index: 0 <= index < bitVec.bits.
  • end -> Number for index: 0 <= index < bitVec.bits.
  • value -> The value to set the index to (0 or 1).
Returns

Returns this with bits set.

Example
bitVec.setRange(2, 6);

clearRange

bitVec.clearRange(begin, end)

Clears a range of bits from begin to end.

Parameters
  • begin -> Number for index: 0 <= index < bitVec.bits.
  • end -> Number for index: 0 <= index < bitVec.bits.
Returns

Returns this with bits cleared.

Example
bitVec.clearRange(2, 6);

equals

bitVec.equals(otherBitVec)

Determines if two bit vectors are equal.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns Boolean true if the two bit vectors are equal, false otherwise.

Example
bitVec.equals(otherBitVec);

notEquals

bitVec.notEquals(otherBitVec)

Determines if two bit vectors are not equal.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns Boolean true if the two bit vectors are equal, false otherwise.

Example
bitVec.notEquals(otherBitVec);

or

bitVec.or(otherBitVec)

Performs the bitwise or operation between two BitVectors and returns the result as a new BitVector object.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns new BitVector object with the result of the operation.

Example
bitVec.or(otherBitVec);

xor

bitVec.xor(otherBitVec)

Performs the bitwise xor operation between two BitVectors and returns the result as a new BitVector object.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns new BitVector object with the result of the operation.

Example
bitVec.xor(otherBitVec);

and

bitVec.and(otherBitVec)

Performs the bitwise and operation between two BitVectors and returns the result as a new BitVector object.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns new BitVector object with the result of the operation.

Example
bitVec.and(otherBitVec);

not

bitVec.not()

Performs the bitwise not operation between two BitVectors and returns the result as a new BitVector object.

Parameters
  • None
Returns

Returns new BitVector object with the result of the operation.

Example
bitVec.not();

invert

bitVec.invert()

Inverts this BitVector, alias of .not().

Parameters
  • None
Returns

Returns new BitVector object with the result of the operation.

Example
bitVec.invert();

orEqual

bitVec.orEqual(otherBitVec)

Performs the bitwise or operation between two BitVectors and assigns the result to this BitVector.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns this for chaining with the bits set.

Example
bitVec.orEqual(otherBitVec);

xorEqual

bitVec.xorEqual(otherBitVec)

Performs the bitwise xor operation between two BitVectors and assigns the result to this BitVector.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns this for chaining with the bits set.

Example
bitVec.xorEqual(otherBitVec);

andEqual

bitVec.andEqual(otherBitVec)

Performs the bitwise and operation between two BitVectors and assigns the result to this BitVector.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns this for chaining with the bits set.

Example
bitVec.andEqual(otherBitVec);

notEqual

bitVec.notEqual(otherBitVec)

Performs the bitwise not operation between two BitVectors and assigns the result to this BitVector.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns this for chaining with the bits set.

Example
bitVec.notEqual(otherBitVec);

isEmpty

bitVec.isEmpty()

Tests whether this BitVector has any set bits.

Parameters
  • bitVec -> BitVector, instance of BitVector class.
Returns

Returns Boolean true if the bit vector has no set bits, false otherwise.

Example
bitVec.isEmpty();

License

See LICENSE file.

Resources