org.knime.core.data.vector.bitvector
Class DenseBitVectorCellFactory

java.lang.Object
  extended by org.knime.core.data.vector.bitvector.DenseBitVectorCellFactory

public class DenseBitVectorCellFactory
extends Object

Used to created DataCells holding a DenseBitVector. As data cells are read only this factory can be used to initialize the bit vector accordingly and then create a data cell from it.
This factory also provides methods for performing basic operations (and(BitVectorValue, BitVectorValue), or(BitVectorValue, BitVectorValue), etc.) on two data cells holding bit vectors.

Author:
ohl, University of Konstanz

Constructor Summary
DenseBitVectorCellFactory(DenseBitVector vector)
          A copy of the specified vector is stored in the created bit vector cell.
DenseBitVectorCellFactory(DenseBitVectorCell cell, long startIdx, long endIdx)
          Initializes the vector from a subsequence of the specified cell.
DenseBitVectorCellFactory(long length)
          Initializes the factory to the specified length, all bits cleared.
DenseBitVectorCellFactory(long[] bits, long length)
          Initializes the factory to the specified length, initializing the bits from the passed array.
DenseBitVectorCellFactory(String hexString)
          Initializes the created bit vector from the hex representation in the passed string.
 
Method Summary
static DenseBitVectorCell and(BitVectorValue bv1, BitVectorValue bv2)
          Creates a dense bit vector cell containing the result of the AND operation on the passed operands.
 void clear(long bitIndex)
          Clears the bit with the specified index in the vector.
 DenseBitVectorCell createDataCell()
          Creates a DataCell from the currently stored bit vector.
static DenseBitVectorCell or(BitVectorValue bv1, BitVectorValue bv2)
          Creates a dense bit vector cell containing the result of the OR operation on the passed operands.
 void set(long bitIndex)
          Sets the bit with the specified index in the vector.
 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.
static SparseBitVectorCell xor(BitVectorValue bv1, BitVectorValue bv2)
          Creates a dense bit vector cell containing the result of the XOR operation on the passed operands.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DenseBitVectorCellFactory

public DenseBitVectorCellFactory(long length)
Initializes the factory to the specified length, all bits cleared.

Parameters:
length - of the vector in the cell to create

DenseBitVectorCellFactory

public DenseBitVectorCellFactory(long[] bits,
                                 long length)
Initializes the factory to the specified length, initializing the bits from the passed array. The array must be build like the one returned by the DenseBitVector.getAllBits() method.

Parameters:
bits - the array containing the initial values of the vector
length - 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.
Throws:
IllegalArgumentException - if length is negative or MAX_VALUE, or if the length of the argument array is less than (length - 1) >> 6) + 1

DenseBitVectorCellFactory

public DenseBitVectorCellFactory(DenseBitVector vector)
A copy of the specified vector is stored in the created bit vector cell.

Parameters:
vector - used to initialize the bits.

DenseBitVectorCellFactory

public DenseBitVectorCellFactory(DenseBitVectorCell cell,
                                 long startIdx,
                                 long endIdx)
Initializes the vector from a subsequence of the specified cell. The bits used are the ones from startIdx to endIdx - 1. The length of the resulting vector is startIdx - endIdx.

Parameters:
cell - the bit vector cell to take the subsequence from.
startIdx - the first bit to include in the created bit vector
endIdx - the first bit NOT to include in the result vector

DenseBitVectorCellFactory

public DenseBitVectorCellFactory(String hexString)
Initializes the created bit vector from the hex representation in the passed string. Only characters '0' - '9' 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).

Parameters:
hexString - containing the hex value to initialize the vector with
Throws:
IllegalArgumentException - if hexString contains characters other then the hex characters (i.e. 0 - 9, A - F)
Method Detail

set

public void set(long bitIndex)
Sets the bit with the specified index in the vector.

Parameters:
bitIndex - the index of the bit to set to one.

set

public void set(long startIdx,
                long endIdx)
Sets all bits in the specified range. The bit at index startIdx is included, the endIdx is not included in the change. The endIdx can't be smaller than the startIdx. If the indices are equal, no change is made.

Parameters:
startIdx - the index of the first bit to set to one
endIdx - the index of the last bit to set to one

set

public void set(long bitIdx,
                boolean value)
Sets the bit at the specified index to the new value.

Parameters:
bitIdx - the index of the bit to set or clear
value - if true, the specified bit will be set, otherwise it will be cleared.
Throws:
ArrayIndexOutOfBoundsException - if the index is negative or larger than the size of the vector

clear

public void clear(long bitIndex)
Clears the bit with the specified index in the vector.

Parameters:
bitIndex - the index of the bit to set to zero.

createDataCell

public DenseBitVectorCell createDataCell()
Creates a DataCell from the currently stored bit vector.

Returns:
a DataCell containing the current value of the vector

and

public static DenseBitVectorCell and(BitVectorValue bv1,
                                     BitVectorValue bv2)
Creates a dense bit vector cell containing the result of the AND operation on the passed operands. The length of the result vector is the maximum of the lengths of the operands.
NOTE: This method performs best if the two arguments are both DenseBitVectorCells. All other implementations need to access the bits through get/set methods which probably performs very poorly.
See also SparseBitVectorCellFactory.and(BitVectorValue, BitVectorValue) for ANDing sparse bit vector cells.

Parameters:
bv1 - the first operand to AND with the other
bv2 - the other operand to AND with the first one
Returns:
the result of the AND operation

or

public static DenseBitVectorCell or(BitVectorValue bv1,
                                    BitVectorValue bv2)
Creates a dense bit vector cell containing the result of the OR operation on the passed operands. The length of the result vector is the maximum of the lengths of the operants.
NOTE: This method performs best if the two arguments are both DenseBitVectorCells. All other implementations need to access the bits through get/set methods which probably performs very poorly.
See also SparseBitVectorCellFactory.and(BitVectorValue, BitVectorValue) for ORing sparse bit vector cells.

Parameters:
bv1 - the first operand to OR with the other
bv2 - the other operand to OR with the first one
Returns:
the result of the OR operation

xor

public static SparseBitVectorCell xor(BitVectorValue bv1,
                                      BitVectorValue bv2)
Creates a dense bit vector cell containing the result of the XOR operation on the passed operands. The length of the result vector is the maximum of the lengths of the operants.
NOTE: This method performs best if the two arguments are both SparseBitVectorCells. All other implementations need to access the bits through get/set methods which probably performs very poorly.
See also SparseBitVectorCellFactory.and(BitVectorValue, BitVectorValue) for XORing sparse bit vector cells.

Parameters:
bv1 - the first operand to XOR with the other
bv2 - the other operand to XOR with the first one
Returns:
the result of the XOR operation


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.