A bit-set implementation in pure JavaScript.
Inspired by, and based on, the Coffeescript bitset implementation by Tom de Grunt (https://github.com/tdegrunt/bitset)
All bit positions are 0-based. That is, the least significant bit is bit 0.
Bit positions may be specified by either their index or their name, if the name is defined in the names mapping.
var bs = new BitSet(names, bytes);
- names is an optional object mapping names to bit indicies.
- bytes is an optional array of 32-bit integers (words) specifying the initial contents of the BitSet. The least significant word should be at index 0.
var factory = BitSet.factory(names);
var bs = factory(bytes);
names and bytes serve the same role as in the full constructor.
This method of construction serves as a shortcut for creating many BitSets that all share the same set of named bits.
Sets the bit at pos to value or true, if value is ommitted.
Returns this
Clears the bit at pos. Equivalent to bs.set(pos, false)
.
Returns this
Gets the value of the bit at pos.
Returns true if the bit is set, false otherwise.
Toggles the state of the bit at pos.
Returns this
Returns the number of words used by the BitSet to represent the bits.
Returns the logical length of the BitSet (i.e., the index of the highest set bit + 1)
Returns the number of bits which are set.
Performs a logical OR of this BitSet and the argument BitSet.
The result is stored in this BitSet.
Returns this.
Performs a logical AND of this BitSet and the argument BitSet.
The result is stored in this BitSet.
Returns this.
Performs a logical AND NOT of this BitSet and the argument BitSet.
The result is stored in this BitSet.
Returns this.
Performs a logical XOR of this BitSet and the argument BitSet.
The result is stored in this BitSet.
Returns this.
Returns true if this BitSet and the argument BitSet have bits in common, otherwise returns false.
Returns true if this BitSet has no bits set (i.e., the cardinality is 0).
Clears all bits in the BitSet.
Returns this.
Returns true if this BitSet contains exactly the same bits as the argument BitSet.
Creates a copy of the BitSet which may be modified independently.
Returns the copy.
Makes this BitSet a copy of the argument BitSet.
Returns this
Returns a string representation of the BitSet.
Example: For a BitSet with bits 0, 5, and 8 set, toString() would return "{0,5,8}"
Returns a big-endian binary string representation of the BitSet.
Returns a hexadecimal string representation of the BitSet.