Class: BitSet

BitSet

This class implements an vector of bits. The size is given at creation time. Each component of the bit set has a boolean value. The bits of a BitSet are indexed by nonnegative integers. Individual indexed bits can be examined, set, or cleared. By default, all bits in the set initially have the value false. Reference:http://en.wikipedia.org/wiki/Bit_array

new BitSet(size)

Example

var BitSet = require("dsjslib").BitSet
var bitset=new BitSet(1024)
Parameters:
Name Type Description
size Number

maximum allowed size of the BitSet

Source:

Methods

and(oBitSet)

Logical AND with other BitSet. The current BitSet is modified as a result of this operation

Parameters:
Name Type Description
oBitSet BitSet

The BitSet to logically AND this BitSet with

Source:

cardinality() → {Number}

Return the number of bits set to true in this BitSet Courtesy Hacker's Delight 5.1

Source:
Returns:

number of bits set to true in this BitSet

Type
Number

clear(bitIndex)

Parameters:
Name Type Argument Description
bitIndex Number <optional>

Set the bit at bitIndex to false. Clears all bits if bitIndex is not provided

Source:

flip(bitIndex)

Sets the bit at the specified index to the complement of its current value.

Parameters:
Name Type Description
bitIndex

Index for the operation

Source:
Throws:
Out of range if bitIndex given is greater than the size
Type
Error

get(bitIndex) → {Boolean}

Examine a bit.

Parameters:
Name Type Description
bitIndex
Source:
Returns:

Returns true if the bit at bitIndex is set, false otherwise.

Type
Boolean

set(bitIndex)

Set the bit at bitIndex to 'true'. Throws out of range error if bit index is greater than the specified size during creation

Parameters:
Name Type Description
bitIndex Number

index to set

Source: