1.0.1 • Published 8 years ago

node-bitmap-ewah v1.0.1

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

node-bitmap-ewah

A set of NodeJS bindings for a compressed bitmap data structure.

Installation

# We use node-gyp to build our binaries
npm install -g node-gyp

# Install node-bitmap-ewah
npm install node-bitmap-ewah

Usage

var Bitmap = require('node-bitmap-ewah');

var bitmap = Bitmap.createObject();

API

  • createObject()
  • push()
  • set()
  • unset()
  • toString()
  • length()
  • numberOfOnes()
  • map()
  • or()
  • and()
  • not()
  • write()
  • read()

createObject()

createObject() is the main entry point for creating a new compressed bitmap instance.

push(bit_pos)

push() appends a set bit (1) to the bitmap in position bit_pos. All bits between the last set bit and bit_pos are appended as unset bits (0).

set(bit_pos)

set() sets the bit in position bit_pos, provided it is already appended. Has no effect if bit is already set.

unset(bit_pos)

unset() unsets the bit in position bit_pos, provided it is already appended. Has no effect if bit is already unset.

toString(delimeter)

toString() returns a string containing the positions of set bits, separated with the delimeter character.

length()

length() returns the uncopressed bitmap's size in bits.

numberOfOnes()

numberOfOnes() returns the number of set bits in the bitmap.

map(callback)

map() returns an array with the results of calling the callback function on each bit positiion that is set.

or(bitmap)

or() applies the logical OR between two bitmaps.

and(bitmap)

and() applies the logical AND between two bitmaps.

not()

not() applies the logical NOT to a bitmap.

write()

write() can be used to store a bitmap to persistent storage. It returns a three element array which contains the bitmap's size in bits (1st position), the size (in words) of the underlying C++ STL vector (2nd positions) and a NodeJS Buffer class object representing the bitmap's content (3rd position).

read(sizeInBits, bufferSisze, Buffer)

read() can be used to retriece a bitmap stored in persistent storage. It takes as argument an array of the same format as returned from the write() function