Skip to content

Latest commit

 

History

History
90 lines (71 loc) · 3.26 KB

README.md

File metadata and controls

90 lines (71 loc) · 3.26 KB

node-bitmap-ewah

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

Inspired by node-ewah (installation fails due to deprecated use of node-waf).

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()

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] (https://nodejs.org/api/buffer.html#buffer_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