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 |
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
-
cardinality() → {Number}
-
Return the number of bits set to true in this BitSet Courtesy Hacker's Delight 5.1
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
-
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
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
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