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

java.lang.Object
  extended by org.knime.core.data.DataCell
      extended by org.knime.core.data.vector.bitvector.DenseBitVectorCell
All Implemented Interfaces:
Serializable, DataValue, BitVectorValue

public class DenseBitVectorCell
extends DataCell
implements BitVectorValue

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).

Author:
ohl, University of Konstanz
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.knime.core.data.vector.bitvector.BitVectorValue
BitVectorValue.BitVectorUtilityFactory
 
Nested classes/interfaces inherited from interface org.knime.core.data.DataValue
DataValue.UtilityFactory
 
Field Summary
static DataType TYPE
          Convenience access member for DataType.getType(DenseBitVectorCell.class).
 
Fields inherited from interface org.knime.core.data.vector.bitvector.BitVectorValue
UTILITY
 
Constructor Summary
DenseBitVectorCell(DenseBitVector bitVector)
          Use the DenseBitVectorCellFactory to create instances of this cell.
 
Method Summary
 long cardinality()
          Returns the number of set bits (bits with value '1') in the vector.
protected  boolean equalsDataCell(DataCell dc)
          Derived classes implement their specific equals function here.
 boolean get(long index)
          Returns the value of the specified bit.
 DenseBitVector getBitVectorCopy()
          Returns a clone of the internal dense bit vector.
static DataCellSerializer<DenseBitVectorCell> getCellSerializer()
          Returns the factory to read/write DataCells of this class from/to a DataInput/DataOutput.
static Class<? extends DataValue> getPreferredValueClass()
          Returns the preferred value class of this cell implementation.
 int hashCode()
          This method must be implemented in order to ensure that two equal DataCell objects return the same hash code.
 boolean isEmpty()
          Returns true, if all bits in the vector are cleared.
 long length()
          Returns the length of the bit 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.
 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 the String representation of this cell's value.
 
Methods inherited from class org.knime.core.data.DataCell
equals, getType, isMissing
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final DataType TYPE
Convenience access member for DataType.getType(DenseBitVectorCell.class).

See Also:
DataType.getType(Class)
Constructor Detail

DenseBitVectorCell

DenseBitVectorCell(DenseBitVector bitVector)
Use the DenseBitVectorCellFactory to create instances of this cell.

Parameters:
bitVector - the bit vector to store in this cell.
Method Detail

getPreferredValueClass

public static final Class<? extends DataValue> getPreferredValueClass()
Returns the preferred value class of this cell implementation. This method is called per reflection to determine which is the preferred renderer, comparator, etc.

Returns:
BitVectorValue.class;

getCellSerializer

public static final DataCellSerializer<DenseBitVectorCell> getCellSerializer()
Returns the factory to read/write DataCells of this class from/to a DataInput/DataOutput. This method is called via reflection.

Returns:
A serializer for reading/writing cells of this kind.
See Also:
DataCell

equalsDataCell

protected boolean equalsDataCell(DataCell dc)
Derived classes implement their specific equals function here. The argument is guaranteed to be not null or a missing value, to be of the same class like this.

Specified by:
equalsDataCell in class DataCell
Parameters:
dc - the cell to compare this to
Returns:
true if this is equal to the argument, false if not

hashCode

public int hashCode()
This method must be implemented in order to ensure that two equal DataCell objects return the same hash code.

Specified by:
hashCode in class DataCell
Returns:
the hash code of your specific DataCell
See Also:
Object.hashCode(), DataCell.equals(java.lang.Object)

toString

public String toString()
Returns the String representation of this cell's value.

Specified by:
toString in class DataCell
Returns:
a String representation of this cell's value

toHexString

public String toHexString()
Returns the hex representation of the bits in this vector. Each character in the result represents 4 bits (with the characters '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 ...).

Specified by:
toHexString in interface BitVectorValue
Returns:
the hex representation of this bit vector.

toBinaryString

public String toBinaryString()
Returns the binary string representation of the bits in this vector. Each character in the result represents one bit - a '1' stands for a set bit, a '0' represents a cleared bit. The character at string position (length - 1) holds the bit with index 0, 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 - 3) (i.e. 2147483644), the result is truncated (and ends with ...).

Specified by:
toBinaryString in interface BitVectorValue
Returns:
the binary (0/1) representation of this bit vector.

getBitVectorCopy

public DenseBitVector getBitVectorCopy()
Returns a clone of the internal dense bit vector.

Returns:
a copy of the internal dense bit vector.

cardinality

public long cardinality()
Returns the number of set bits (bits with value '1') in the vector.

Specified by:
cardinality in interface BitVectorValue
Returns:
the number of set bits (bits with value '1') in the vector.

get

public boolean get(long index)
Returns the value of the specified bit.

Specified by:
get in interface BitVectorValue
Parameters:
index - the index of the bit to test
Returns:
true if the bit at the specified index is set, false if it is zero.

isEmpty

public boolean isEmpty()
Returns true, if all bits in the vector are cleared.

Specified by:
isEmpty in interface BitVectorValue
Returns:
true, if all bits are zero, false, if at least one bit is set.

length

public long length()
Returns the length of the bit vector. The number of stored bits.

Specified by:
length in interface BitVectorValue
Returns:
the number of bits stored in the vector

nextClearBit

public long nextClearBit(long startIdx)
Finds the next bit not set (that is '0') on or after the specified index. Returns an index larger than or equal the provided index, or -1 if no bit is cleared after the startIdx. (It is okay to pass an index larger than the length of the vector.)

Specified by:
nextClearBit in interface BitVectorValue
Parameters:
startIdx - the first index to look for '0's.
Returns:
the index of the next cleared bit, which is on or after the provided startIdx. Or -1 if the vector contains no zero anymore.

nextSetBit

public long nextSetBit(long startIdx)
Finds the next bit set to one on or after the specified index. Returns an index larger than or equal the provided index, or -1 if no bit is set after the startIdx. (Is okay to pass an index larger than the length of the vector.)

Specified by:
nextSetBit in interface BitVectorValue
Parameters:
startIdx - the first index to look for '1's. (It is allowed to pass an index larger then the vector's length.)
Returns:
the index of the next bit set to one, which is on or after the provided startIdx.


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.