Object
IntBitSet
BitSet implementation which uses ints to represent words.
Java standard BitSet
uses long as a word which means if you need to obtain
all words as an array of integers you will need to create a new int array and copy all bits from
BitSet.
When this is done very often it can decrease performance.
This class is using int as word so it is possible to obtain array of integers with no cost.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
flip
(int i) Flip single bit by its positionvoid
flip
(int fromIndex, int toIndex) Flips all bits between [fromIndex, toIndex)int
flip
(int word, int fromIndex, int toIndex) int[]
intArray()
int
nextSetBit
(int fromIndex) Returns the index of the first bit that is set to true that occurs on or after the specified starting index.
-
Constructor Details
-
IntBitSet
public IntBitSet(int len) - Parameters:
len
- number of bits which are going to be stored
-
IntBitSet
public IntBitSet(int[] array) - Parameters:
array
- creates newIntBitSet
backed up by given array
-
-
Method Details
-
flip
public void flip(int fromIndex, int toIndex) Flips all bits between [fromIndex, toIndex) -
flip
public int flip(int word, int fromIndex, int toIndex) -
flip
public void flip(int i) Flip single bit by its position -
intArray
public int[] intArray()- Returns:
- internal int array
-
nextSetBit
public int nextSetBit(int fromIndex) Returns the index of the first bit that is set to true that occurs on or after the specified starting index. If no such bit exists then return -1 -
toBinaryString
-