|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mahout.math.PersistentObject
org.apache.mahout.math.bitvector.BitVector
@Deprecated public class BitVector
Constructor Summary | |
---|---|
BitVector(int size)
Deprecated. Constructs a bit vector that holds size bits. |
|
BitVector(long[] bits,
int size)
Deprecated. You normally need not use this method. |
Method Summary | |
---|---|
void |
and(BitVector other)
Deprecated. Performs a logical AND of the receiver with another bit vector (A = A & B). |
void |
andNot(BitVector other)
Deprecated. Clears all of the bits in receiver whose corresponding bit is set in the other bitvector (A = A \ B). |
int |
cardinality()
Deprecated. Returns the number of bits currently in the true state. |
protected void |
checkSize(BitVector other)
Deprecated. Sanity check for operations requiring another bitvector with at least the same size. |
void |
clear()
Deprecated. Clears all bits of the receiver. |
void |
clear(int bitIndex)
Deprecated. Changes the bit with index bitIndex to the "clear" (false) state. |
java.lang.Object |
clone()
Deprecated. Cloning this BitVector produces a new BitVector that is equal to it. |
BitVector |
copy()
Deprecated. Returns a deep copy of the receiver; calls clone() and casts the result. |
long[] |
elements()
Deprecated. You normally need not use this method. |
void |
elements(long[] bits,
int size)
Deprecated. You normally need not use this method. |
boolean |
equals(java.lang.Object obj)
Deprecated. Compares this object against the specified object. |
boolean |
forEachIndexFromToInState(int from,
int to,
boolean state,
IntProcedure procedure)
Deprecated. Applies a procedure to each bit index within the specified range that holds a bit in the given state. |
boolean |
get(int bitIndex)
Deprecated. Returns from the bitvector the value of the bit with the specified index. |
long |
getLongFromTo(int from,
int to)
Deprecated. Returns a long value representing bits of the receiver from index from to index to. |
boolean |
getQuick(int bitIndex)
Deprecated. Returns from the bitvector the value of the bit with the specified index; WARNING: Does not check preconditions. |
int |
hashCode()
Deprecated. Returns a hash code value for the receiver. |
int |
indexOfFromTo(int from,
int to,
boolean state)
Deprecated. Returns the index of the first occurrence of the specified state. |
void |
not()
Deprecated. Performs a logical NOT on the bits of the receiver (A = ~A). |
protected int |
numberOfBitsInPartialUnit()
Deprecated. Returns the number of bits used in the trailing PARTIAL unit. |
protected int |
numberOfFullUnits()
Deprecated. Returns the number of units that are FULL (not PARTIAL). |
void |
or(BitVector other)
Deprecated. Performs a logical OR of the receiver with another bit vector (A = A | B). |
BitVector |
partFromTo(int from,
int to)
Deprecated. Constructs and returns a new bit vector which is a copy of the given range. |
void |
put(int bitIndex,
boolean value)
Deprecated. Sets the bit with index bitIndex to the state specified by value. |
void |
putLongFromTo(long value,
int from,
int to)
Deprecated. Sets bits of the receiver from index from to index to to the bits of value . |
void |
putQuick(int bitIndex,
boolean value)
Deprecated. Sets the bit with index bitIndex to the state specified by value; WARNING: Does not check preconditions. |
void |
replaceFromToWith(int from,
int to,
BitVector source,
int sourceFrom)
Deprecated. Replaces the bits of the receiver in the given range with the bits of another bit vector. |
void |
replaceFromToWith(int from,
int to,
boolean value)
Deprecated. Sets the bits in the given range to the state specified by value. |
void |
set(int bitIndex)
Deprecated. Changes the bit with index bitIndex to the "set" (true) state. |
void |
setSize(int newSize)
Deprecated. Shrinks or expands the receiver so that it holds newSize bits. |
int |
size()
Deprecated. Returns the size of the receiver. |
java.lang.String |
toString()
Deprecated. Returns a string representation of the receiver. |
void |
xor(BitVector other)
Deprecated. Performs a logical XOR of the receiver with another bit vector (A = A ^ B). |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BitVector(long[] bits, int size)
A bitvector is modelled as a long array, i.e. long[] bits holds bits of a bitvector. Each long value holds 64 bits. The i-th bit is stored in bits[i/64] at bit position i % 64 (where bit position 0 refers to the least significant bit and 63 refers to the most significant bit).
java.lang.IllegalArgumentException
- if size < 0 || size > bits.length*64.public BitVector(int size)
size
- the number of bits the bit vector shall have.
java.lang.IllegalArgumentException
- if size < 0.Method Detail |
---|
public void and(BitVector other)
true
if and only if it already had the value true
and the
corresponding bit in the other bit vector argument has the value true
.
other
- a bit vector.
java.lang.IllegalArgumentException
- if size() > other.size().public void andNot(BitVector other)
other
- a bitvector with which to mask the receiver.
java.lang.IllegalArgumentException
- if size() > other.size().public int cardinality()
protected void checkSize(BitVector other)
public void clear()
public void clear(int bitIndex)
bitIndex
- the index of the bit to be cleared.
java.lang.IndexOutOfBoundsException
- if bitIndex<0 || bitIndex>=size()public java.lang.Object clone()
BitVector
produces a new BitVector
that is equal to it. The clone of the bit
vector is another bit vector that has exactly the same bits set to true
as this bit vector and the
same current size, but independent state.
clone
in class PersistentObject
public BitVector copy()
clone()
and casts the result.
public long[] elements()
A bitvector is modelled as a long array, i.e. long[] bits holds bits of a bitvector. Each long value holds 64 bits. The i-th bit is stored in bits[i/64] at bit position i % 64 (where bit position 0 refers to the least significant bit and 63 refers to the most significant bit).
public void elements(long[] bits, int size)
A bitvector is modelled as a long array, i.e. long[] bits holds bits of a bitvector. Each long value holds 64 bits. The i-th bit is stored in bits[i/64] at bit position i % 64 (where bit position 0 refers to the least significant bit and 63 refers to the most significant bit).
bits
- the backing bits of the bit vector.size
- the number of bits the bit vector shall hold.
java.lang.IllegalArgumentException
- if size < 0 || size > bits.length*64.public boolean equals(java.lang.Object obj)
true
if and only if the argument is
not null
and is a BitVector
object that has the same size as the receiver and the same
bits set to true
as the receiver. That is, for every nonnegative int
index
k
,
((BitVector)obj).get(k) == this.get(k)must be true.
equals
in class java.lang.Object
obj
- the object to compare with.
true
if the objects are the same; false
otherwise.public boolean forEachIndexFromToInState(int from, int to, boolean state, IntProcedure procedure)
Optimized for speed. Particularly quick if one of the following conditions holds
from
- the leftmost search position, inclusive.to
- the rightmost search position, inclusive.state
- element to search for.procedure
- a procedure object taking as argument the current bit index. Stops iteration if the procedure
returns false, otherwise continues.
java.lang.IndexOutOfBoundsException
- if (size()>0 && (from<0 || from>to || to>=size())).public boolean get(int bitIndex)
bitIndex
- the bit index.
java.lang.IndexOutOfBoundsException
- if bitIndex<0 || bitIndex>=size()public long getLongFromTo(int from, int to)
from
, ..., bit
to-from
set to bit to
. All other bits of the return value are set to 0. If
to-from+1==0 then returns zero (0L).
from
- index of start bit (inclusive).to
- index of end bit (inclusive).
java.lang.IndexOutOfBoundsException
- if from<0 || from>=size() || to<0 || to>=size() || to-from+1<0 ||
to-from+1>64public boolean getQuick(int bitIndex)
Provided with invalid parameters this method may return invalid values without throwing any exception. You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): bitIndex >= 0 && bitIndex < size().
bitIndex
- the bit index.
public int hashCode()
Suppose the bits in the receiver were to
be stored in an array of long
integers called, say, bits
, in such a manner that bit
k
is set in the receiver (for nonnegative values of k
) if and only if the expression
((k>>6) < bits.length) && ((bits[k>>6] & (1L << (bit & 0x3F))) != 0)is true. Then the following definition of the
hashCode
method would be a correct implementation of the
actual algorithm:
public int hashCode() { long h = 1234; for (int i = bits.length; --i >= 0; ) { h ^= bits[i] * (i + 1); } return (int)((h >> 32) ^ h); }Note that the hash code values change if the set of bits is altered.
hashCode
in class java.lang.Object
public int indexOfFromTo(int from, int to, boolean state)
-1
if the receiver does not
contain this state. Searches between from
, inclusive and to
, inclusive. Optimized for speed. Preliminary performance (200Mhz Pentium Pro, JDK 1.2, NT): size=10^6, from=0, to=size-1, receiver contains matching state in the very end --> 0.002 seconds elapsed time.
state
- state to search for.from
- the leftmost search position, inclusive.to
- the rightmost search position, inclusive.
-1
if the element is
not found.
java.lang.IndexOutOfBoundsException
- if (size()>0 && (from<0 || from>to || to>=size())).public void not()
protected int numberOfBitsInPartialUnit()
protected int numberOfFullUnits()
public void or(BitVector other)
true
if and only if it either already had the value true
or the
corresponding bit in the other bit vector argument has the value true
.
other
- a bit vector.
java.lang.IllegalArgumentException
- if size() > other.size().public BitVector partFromTo(int from, int to)
from
- the start index within the receiver, inclusive.to
- the end index within the receiver, inclusive.
java.lang.IndexOutOfBoundsException
- if size()>0 && (from<0 || from>to || to>=size())).public void put(int bitIndex, boolean value)
bitIndex
- the index of the bit to be changed.value
- the value to be stored in the bit.
java.lang.IndexOutOfBoundsException
- if bitIndex<0 || bitIndex>=size()public void putLongFromTo(long value, int from, int to)
from
to index to
to the bits of value
.
Bit from
is set to bit 0 of value
, ..., bit to
is set to bit
to-from
of value
. All other bits stay unaffected. If to-from+1==0 then does
nothing.
value
- the value to be copied into the receiver.from
- index of start bit (inclusive).to
- index of end bit (inclusive).
java.lang.IndexOutOfBoundsException
- if from<0 || from>=size() || to<0 || to>=size() || to-from+1<0 ||
to-from+1>64.public void putQuick(int bitIndex, boolean value)
Provided with invalid parameters this method may set invalid values without throwing any exception. You should only use this method when you are absolutely sure that the index is within bounds. Precondition (unchecked): bitIndex >= 0 && bitIndex < size().
bitIndex
- the index of the bit to be changed.value
- the value to be stored in the bit.public void replaceFromToWith(int from, int to, BitVector source, int sourceFrom)
Optimized for speed. Preliminary performance (200Mhz Pentium Pro, JDK 1.2, NT): replace 10^6 ill aligned bits --> 0.02 seconds elapsed time.
from
- the start index within the receiver, inclusive.to
- the end index within the receiver, inclusive.source
- the source bitvector to copy from.sourceFrom
- the start index within source, inclusive.
java.lang.IndexOutOfBoundsException
- if size()>0 && (from<0 || from>to || to>=size() || sourceFrom<0
|| sourceFrom+to-from+1>source.size())).public void replaceFromToWith(int from, int to, boolean value)
Optimized for speed. Preliminary performance (200Mhz Pentium Pro, JDK 1.2, NT): replace 10^6 ill aligned bits --> 0.002 seconds elapsed time.
from
- the start index, inclusive.to
- the end index, inclusive.value
- the value to be stored in the bits of the range.
java.lang.IndexOutOfBoundsException
- if size()>0 && (from<0 || from>to || to>=size()).public void set(int bitIndex)
bitIndex
- the index of the bit to be set.
java.lang.IndexOutOfBoundsException
- if bitIndex<0 || bitIndex>=size()public void setSize(int newSize)
newSize
- the number of bits the bit vector shall have.
java.lang.IllegalArgumentException
- if size < 0.public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public void xor(BitVector other)
true
if and only if one of the following statements holds: true
, and the corresponding bit in the argument has the value
false
. false
, and the corresponding bit in the
argument has the value true
.
other
- a bit vector.
java.lang.IllegalArgumentException
- if size() > other.size().
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |