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-vector.jsx

v0.4.0

Published

BitVector implementation for JSX/JS/AMD/CommonJS

Downloads

11

Readme

bit-vector.jsx

Synopsis

Succinct Bit Vector implementation for JSX/JS/AMD/CommonJS

Motivation

This code is a part of Oktavia. Bit Vector is used to reduce memory foot print to store suffix array and provides some high speed operation in O(1) - O(N).

Code Example

Use from JSX

import "bit-vector.jsx";

class _Main {
    static function main(argv : string[]) : void
    {
        // Rank: number of bits before specified position

        var bv = new Uint32BitVector(8);
        bv.set(2);
        bv.set(3);
        bv.set(6):
        bv.build(); // 00110010

        console.log(bv.rank(0)); // -> 0
        console.log(bv.rank(1)); // -> 0
        console.log(bv.rank(2)); // -> 1
        console.log(bv.rank(3)); // -> 2
        console.log(bv.rank(4)); // -> 2
        console.log(bv.rank(5)); // -> 2
        console.log(bv.rank(6)); // -> 3
        console.log(bv.rank(7)); // -> 3

        // Compress array that has many empty spaces by using BitVector.rank()
        var original = [0, 0, 200, 300, 0, 0, 500, 0]; < 8 x 8 = 64 byte
        var pos = 7;
        var getNum = original[pos]; // => 500;

        var values = [200, 300, 500]; // => 24 byte + 4 byte(uint32).
        var getNum2 = values[bv.rank(pos)]; // => 500; Same value!

        // Select: return x-th bit from first
        console.log(bv.select(0)); // -> 0
        console.log(bv.select(1)); // -> 2
        console.log(bv.select(2)); // -> 3
        console.log(bv.select(3)); // -> 6

        // Find the word that specified character belongs to.
        var words = "hello world succinct bit vector";
        var bv2 = new Uint32BitVector(words.length);
        bv.set(6);
        bv.set(12);
        bv.set(21);
        bv.set(25);
        bv.build();

        console.log(bv.select(10)); // -> 1: 10th character belongs to second word.
    }
}

Use from node.js

var ArrayBitVector = require('bit-vector.common.js').ArrayBitVector;
var Uint32BitVector = require('bit-vector.common.js').Uint32BitVector;

Use from require.js

// use bit-vector.amd.js
define(['bit-vector.jsx'], function (bitvector) {

    ArrayBitVector = bitvector.ArrayBitVector;
    Uint32BitVector = bitvector.Uint32BitVector;
});

Use via standard JSX function

<script src="bit-vector.js}}" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
    var ArrayBitVector = JSX.require("src/bit-vector.js").ArrayBitVector;
    var Uint32BitVector = JSX.require("src/bit-vector.js").Uint32BitVector;
});
</script>

Use via global variables

<script src="bit-vector.global.js}}" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
    var bv = new ArrayBitVector();
    var bv2 = new Uint32BitVector(10);
});
</script>

Installation

$ npm install bit-vector.jsx

API Reference

ArrayBitVector implements BitVector.<number[]>

Constructor for bit vector based on int[]. This version resizes length automatically, but each only memory efficiency is 50%. This is JavaScript limitation because it has only 64bit floating point number and it uses only 32bit part as integer.

Uint32BitVector(size : int) implements BitVector.

Constructor for bit vector based on Uint32bitVector. This version is fixed size, but memory efficiency is better than ArrayBitVector.

BitVector..size() : int

It returns BitVector size. set extends this size.

BitVector..set(pos : int, flag : boolean = true) : void

It sets bit. If flag is false, it inverts bit at specified position.

BitVector..get(pos : int) : boolean

It returns bit of specified position.

BitVector..build() : void

Precalculates rank() number. It should be called before using select() and rank().

BitVector..rank(pos : int, flag : boolean = true) : int

Counts number of bits before specified position. If flag is false it calcs count inverted bits.

BitVector..select(pos : int, flag : boolean = true) : int

Returns x-th bit from first. If flag is false it returns position of specified x-th inverted bits.

Development

JSX

Don't afraid JSX! If you have an experience of JavaScript, you can learn JSX quickly.

  • Static type system and unified class syntax.
  • All variables and methods belong to class.
  • JSX includes optimizer. You don't have to write tricky unreadalbe code for speed.
  • You can use almost all JavaScript API as you know. Some functions become static class functions. See reference.

Setup

To create development environment, call following command:

$ npm install

Repository

  • Repository: git:/github.com/shibukawa/bit-vector.jsx.git
  • Issues: Repository: https:/github.com/shibukawa/bit-vector.jsx/issues

Run Test

$ grunt test

Build

$ grunt build

Generate API reference

$ grunt doc

Author

License

MIT

Complete license is written in LICENSE.md.