|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.data.vector.bitvector.DenseBitVector
public class DenseBitVector
Stores Zeros and Ones in a vector, i.e. with fixed positions. The vector has
a fixed length.
Implementation stores the bits in a collection of longs (64 bit words). Thus
it can be used for well populated vectors. Its length is restricted to
(Integer.MAX_VALUE
- 1) * 64 (i.e. 137438953344, in which case it
uses around 16GigaByte of memory).
The implementation is not thread-safe.
Constructor Summary | |
---|---|
DenseBitVector(DenseBitVector clone)
Creates a new instance as copy of the passed argument. |
|
DenseBitVector(long length)
Creates a new vector of the specified length, with no bits set. |
|
DenseBitVector(long[] bits,
long length)
Creates a new instance taking over the initialization of the bits from the passed array. |
|
DenseBitVector(String hexString)
Initializes the created bit vector from the hex representation in the passed string. |
Method Summary | |
---|---|
DenseBitVector |
and(DenseBitVector bv)
Creates and returns a new bit vector whose bits are set at positions where both, this and the argument vector have their bits set. |
long |
cardinality()
Number of bits set in this bit vector. |
void |
clear(long bitIdx)
Sets the bit at the specified index to one. |
void |
clear(long startIdx,
long endIdx)
Clears all bits in the specified range. |
DenseBitVector |
concatenate(DenseBitVector bv)
Creates and returns a new bit vector that contains copies of both (this and the argument vector). |
String |
dumpBits()
Returns a multi-line dump of the internal storage. |
boolean |
equals(Object obj)
|
boolean |
get(long bitIdx)
Returns true if the bit at the specified index is set. |
long[] |
getAllBits()
Returns a copy of the internal storage of all bits. |
int |
hashCode()
|
boolean |
intersects(DenseBitVector bv)
Returns true, if this and the argument vector have at least one bit set at the same position. |
DenseBitVector |
invert()
Creates and returns a new bit vector whose bits are inverted compared to this vector. |
boolean |
isEmpty()
Returns true if no bits are set in this bit vector. |
long |
length()
Returns the number of bits stored in this vector. |
long |
nextClearBit(long startIdx)
Finds the next bit not set (that is '0') on or after the specified index. |
long |
nextSetBit(long startIdx)
Finds the next bit set to one on or after the specified index. |
DenseBitVector |
or(DenseBitVector bv)
Creates and returns a new bit vector whose bits are set at positions where at least one of the vectors (this or the argument vector) have a bit set. |
void |
set(long bitIdx)
Sets the bit at the specified index to zero. |
void |
set(long bitIdx,
boolean value)
Sets the bit at the specified index to the new value. |
void |
set(long startIdx,
long endIdx)
Sets all bits in the specified range. |
void |
set(long startIdx,
long endIdx,
boolean value)
Sets all bits in the specified range to the new value. |
DenseBitVector |
subSequence(long startIdx,
long endIdx)
Creates and returns a new bit vector that contains a subsequence of this vector, beginning with the bit at index startIdx and with
its last bit being this' bit at position endIdx - 1 . |
String |
toBinaryString()
Returns the binary string representation of the bits in this vector. |
String |
toHexString()
Returns the hex representation of the bits in this vector. |
String |
toString()
Returns a string containing (comma separated) indices of the bits set in this vector. |
DenseBitVector |
xor(DenseBitVector bv)
Creates and returns a new bit vector whose bits are set at positions where (exactly) one of the vectors (this or the argument vector) have a bit set. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DenseBitVector(long length)
length
- the length of the new bit vector.public DenseBitVector(long[] bits, long length)
getAllBits()
method.
bits
- the array containing the initial values of the vectorlength
- the number of bits to use from the array. If the array is
too long (i.e. contains more than length bits) the additional
bits are ignored. If the array is too short, an exception is
thrown.
IllegalArgumentException
- if length is negative or MAX_VALUE, or
if the length of the argument array is less than (length - 1)
>> 6) + 1public DenseBitVector(String hexString)
'0' - '9'
,
'A' - 'F'
and 'a' - 'f'
are allowed. The
character at string position (length - 1)
represents the
bits with index 0 to 3 in the vector. The character at position 0
represents the bits with the highest indices. The length of the vector
created is the length of the string times 4 (as each character represents
four bits).
hexString
- containing the hex value to initialize the vector with
IllegalArgumentException
- if hexString
contains
characters other then the hex characters (i.e.
0 - 9, A - F, and 'a' - 'f'
)public DenseBitVector(DenseBitVector clone)
clone
- the vector to copy into the new instanceMethod Detail |
---|
public long length()
public void set(long bitIdx, boolean value)
bitIdx
- the index of the bit to set or clearvalue
- if true, the specified bit will be set, otherwise it will be
cleared.
ArrayIndexOutOfBoundsException
- if the index is negative or larger
than the size of the vectorpublic void set(long bitIdx)
bitIdx
- the index of the bit to clear.
ArrayIndexOutOfBoundsException
- if the index is negative or larger
than the size of the vectorpublic void set(long startIdx, long endIdx, boolean value)
startIdx
- the index of the first bit to set to the new valueendIdx
- the index of the last bit to set to the new valuevalue
- if set to true the bits are set to one, otherwise to zeropublic void set(long startIdx, long endIdx)
startIdx
- the index of the first bit to set to oneendIdx
- the index of the last bit to set to onepublic void clear(long bitIdx)
bitIdx
- the index of the bit to set.
ArrayIndexOutOfBoundsException
- if the index is negative or larger
than the size of the vectorpublic void clear(long startIdx, long endIdx)
startIdx
- the index of the first bit to set to zeroendIdx
- the index of the last bit to set to zeropublic long cardinality()
public boolean isEmpty()
public boolean intersects(DenseBitVector bv)
bv
- the vector to test
public boolean get(long bitIdx)
bitIdx
- the index of the bit to test.
true
if the specified bit is set,
false
otherwise
ArrayIndexOutOfBoundsException
- if the index is larger than the
length of the vectorpublic long nextSetBit(long startIdx)
startIdx
- the first index to look for '1's. (It is allowed to pass
an index larger then the vector's length.)
ArrayIndexOutOfBoundsException
- if the specified startIdx is
negativepublic long nextClearBit(long startIdx)
startIdx
- the first index to look for '0's.
ArrayIndexOutOfBoundsException
- if the specified startIdx negativepublic DenseBitVector subSequence(long startIdx, long endIdx)
startIdx
and with
its last bit being this' bit at position endIdx - 1
. The
length of the result vector is endIdx - startIdx
. If
startIdx
equals endIdx
a vector of length
zero is returned.
startIdx
- the startIdx of the subsequenceendIdx
- the first bit in this vector after startIdx that is not
included in the result sequence.
endIdx - startIdx
containing the subsequence of this vector from
startIdx
(included) to endIdx
(not
included anymore).public DenseBitVector and(DenseBitVector bv)
bv
- the vector to AND this one with
public DenseBitVector or(DenseBitVector bv)
bv
- the vector to OR this one with
public DenseBitVector xor(DenseBitVector bv)
bv
- the vector to XOR this one with
public DenseBitVector invert()
public DenseBitVector concatenate(DenseBitVector bv)
bv
- the vector to append at the end of this
public int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
public String toString()
toString
in class Object
public String toHexString()
'0'
-
'9'
and 'A'
- 'F'
). The
character at string position (length - 1)
holds the lowest
bits (bit 0 to 3), the character at position 0 represents the bits with
the largest index in the vector. If the length of the vector is larger
than (Integer.MAX_VALUE
- 1) * 4 (i.e. 8589934584), the result
is truncated (and ends with ...).
public String toBinaryString()
(length - 1)
holds the bit with index 0, the character at
position 0 represents the bit with the largest index in the vector. If
the length of the vector is larger than (Integer.MAX_VALUE
- 3)
(i.e. 2147483644), the result is truncated (and ends with ...).
public long[] getAllBits()
public String dumpBits()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |