|
J-Sim v1.2.1-p7 API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectdrcl.DrclObj
drcl.data.BitSet
This class implements a set of bits that grows as needed. Each
bit of the set has a boolean value. The
bits of a BitSet are indexed by nonnegative integers.
Individual indexed bit can be examined, set, or cleared. One
BitSet may be used to modify the contents of another
BitSet through logical AND, logical inclusive OR, and
logical exclusive OR operations.
By default, all bits in the set initially have the value
false.
Every bit set has a size, which is the number of bits in use
by the bit set. Note that the actual size is the actual number of bits
that the bit set is able to represent. The size as well as the actual
size is changed when the bit index of an operation exceeds the sizes.
Also the size can be set explicitly with setSize(int).
The most significant bits are truncated when a smaller size is set.
Bits are packed into arrays of subsets(longs). Each subset
is indexed with nonnegative integers. Index 0 refers to the subset
containing
the first 64 least significant bits. BitSet operations also apply to subsets.
| Field Summary | |
protected int |
nb
|
protected int |
nbset
|
protected int |
nsubsets
|
protected long[] |
subset
The subset in this BitSet. |
| Constructor Summary | |
BitSet()
Creates a new bit set. |
|
BitSet(int nbits_)
Creates a bit set whose initial size is large enough to explicitly represent subset with indices in the range 0 through
nbits-1. |
|
BitSet(int[] set_)
Creates and returns a bit set in which the bits of the positions specified in set_ are set to 1's. |
|
BitSet(int size_,
long value_)
|
|
BitSet(int size_,
long[] values_)
Creates and returns a bit set of the specified size given an array of long integers. |
|
| Method Summary | |
void |
and(BitSet set_)
Performs a logical AND of this target bit set with the argument bit set. |
void |
and(int subsetIndex_,
long subset_)
Performs a logical AND of the target subset with the argument subset. |
java.lang.String |
binaryRepresentation()
Returns the binary representation of this bit set. |
java.lang.String |
binaryRepresentation(boolean skipLeadingZeros_)
Returns the binary representation of this bit set. |
java.lang.String |
binaryRepresentation(int length_)
Returns the binary representation of the bit set in the specified number of binary characters. |
void |
clear()
Clears all the bits. |
void |
clear(int bitIndex_)
Sets the bit specified by the index to false. |
void |
clear(int[] bitIndices_)
Sets the bits specified by the indices to false. |
void |
clearBy(BitSet set_)
Clears all of the subset in this BitSet whose corresponding
bit is set in the specified BitSet. |
void |
clearBy(int subsetIndex_,
long subset_)
Clears the subset in this BitSet whose corresponding
bit is set in the specified subset. |
java.lang.Object |
clone()
Returns a clone of this object. |
void |
duplicate(java.lang.Object source_)
opies the content of the source_ object to this object. |
boolean |
equals(java.lang.Object that_)
Compares this object against the specified object. |
boolean |
get(int bitIndex_)
Returns the value of the bit with the specified index. |
int |
getActualSize()
Returns the number of bits actually used by this BitSet to represent bit values. |
int |
getNumSetBits()
Returns the number of bits that are set true in this bit set. |
int[] |
getSetBitIndices()
Returns the array of indices of the bits that are set true in this bit set. |
int |
getSize()
Returns the "logical size" of this BitSet. |
long |
getSubset(int subsetIndex_)
Returns the subset specified by the index to the argument subset. |
int[] |
getUnsetBitIndices()
Returns the array of indices of the bits that are set false in this bit set. |
int |
hashCode()
Returns a hash code value for this bit set. |
java.lang.String |
hexRepresentation()
Returns the hex representation of this bit set. |
java.lang.String |
hexRepresentation(boolean skipLeadingZeros_)
Returns the hex representation of this bit set. |
java.lang.String |
hexRepresentation(int length_)
Returns the hex representation of the bit set in the specified number of hex characters. |
void |
not()
Performs a logical NOT of the this bitset. |
java.lang.String |
numberRepresentation()
Returns the long integer representation of this bit set. |
void |
or(BitSet set_)
Performs a logical OR of this bit set with the bit set argument. |
void |
or(int subsetIndex_,
long subset_)
Performs a logical OR of the target subset with the argument subset. |
void |
set()
Sets all the bits. |
void |
set(int bitIndex_)
Sets the bit specified by the index to true. |
void |
set(int[] bitIndices_)
Sets the bits specified by the indices to true. |
void |
set(int subsetIndex_,
long subset_)
Sets the subset specified by the index to the argument subset. |
void |
setSize(int size_)
If size_ is larger than the current size,
the bit set expands from the most significant bit and
the new bits are cleared (set to false). |
java.lang.String |
toString()
Prints out this bit set by the set of indices of 1's in this bit set. |
void |
xor(BitSet set_)
Performs a logical XOR of this bit set with the bit set argument. |
void |
xor(int subsetIndex_,
long subset_)
Performs a logical XOR of the target subset with the argument subset. |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected long[] subset
protected int nb
protected int nsubsets
protected int nbset
| Constructor Detail |
public BitSet(int size_,
long value_)
public BitSet(int size_,
long[] values_)
values_[0] is stored
as the least significant bit, and bit 63 of values_[size-1]
as the most significant bit.
public BitSet(int[] set_)
set_ are set to 1's.
The length of the bit set is set to the maximum value in
set_.
public BitSet()
false.
public BitSet(int nbits_)
0 through
nbits-1. All subset are initially false.
java.lang.NegativeArraySizeException - if the specified initial size
is negative.| Method Detail |
public int getSize()
BitSet.
BitSet.public void setSize(int size_)
size_ is larger than the current size,
the bit set expands from the most significant bit and
the new bits are cleared (set to false).
public int getNumSetBits()
public int[] getSetBitIndices()
public int[] getUnsetBitIndices()
public int getActualSize()
BitSet to represent bit values.
The maximum element in the set is the size - 1st element.
BitSet.public void set()
public void set(int bitIndex_)
true.
bitIndex_ - a bit index.
java.lang.IndexOutOfBoundsException - if the specified index is negative.public void set(int[] bitIndices_)
true.
bitIndices_ - array of bit indices.
java.lang.IndexOutOfBoundsException - if the specified index is negative.
public void set(int subsetIndex_,
long subset_)
subsetIndex_ - the subset index.subset_ - the subset with which to mask the corresponding
subset in this BitSet.public void clear()
public void clear(int bitIndex_)
false.
bitIndex_ - the index of the bit to be cleared.
java.lang.IndexOutOfBoundsException - if the specified index is negative.public void clear(int[] bitIndices_)
false.
bitIndices_ - array of bit indices.
java.lang.IndexOutOfBoundsException - if the specified index is negative.public void clearBy(BitSet set_)
BitSet whose corresponding
bit is set in the specified BitSet.
set_ - the BitSet with which to mask this
BitSet.
public void clearBy(int subsetIndex_,
long subset_)
BitSet whose corresponding
bit is set in the specified subset.
This operation does not change the size of the bit set.
subsetIndex_ - the subset index.subset_ - the subset with which to mask the corresponding
subset in this BitSet.public boolean get(int bitIndex_)
true if the bit with the index bitIndex_
is currently set in this BitSet; otherwise, the result
is false.
bitIndex_ - the bit index.
java.lang.IndexOutOfBoundsException - if the specified index is negative.public long getSubset(int subsetIndex_)
subsetIndex_ - the subset index.
java.lang.IndexOutOfBoundsException - if the specified index is negative.public void and(BitSet set_)
true if and only if it both initially
had the value true and the corresponding bit in the
bit set argument also had the value true.
set_ - a bit set.
public void and(int subsetIndex_,
long subset_)
true if and only if it both initially
had the value true and the corresponding bit in the
subset argument also had the value true.
This operation does not change the size of the bit set.
subsetIndex_ - the subset index.subset_ - the subset with which to mask the corresponding
subset in this BitSet.public void or(BitSet set_)
true if and only if it either already had the
value true or the corresponding bit in the bit set
argument has the value true.
This operation does not change the size of the bit set.
set_ - a bit set.
public void or(int subsetIndex_,
long subset_)
true if and only if it both initially
had the value true or the corresponding bit in the
subset argument also had the value true.
subsetIndex_ - the subset index.subset_ - the subset with which to mask the corresponding
subset in this BitSet.public void xor(BitSet set_)
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.
set_ - a bit set.
public void xor(int subsetIndex_,
long subset_)
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.
subsetIndex_ - the subset index.subset_ - the subset with which to mask the corresponding
subset in this BitSet.public void not()
public int hashCode()
BitSet. The algorithm used to compute it may
be described as follows.
Suppose the subset in the BitSet were to be stored
in an array of long integers called, say,
subset, in such a manner that bit k is
set in the BitSet (for nonnegative values of
k) if and only if the expression
((k>>6) < subset.length) && ((subset[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 synchronized int hashCode() {
long h = 1234;
for (int i = subset.length; --i >= 0; ) {
h ^= subset[i] * (i + 1);
}
return (int)((h >> 32) ^ h);
}
Note that the hash code values change if the set of subset is altered.
Overrides the hashCode method of Object.
public boolean equals(java.lang.Object that_)
true if and only if the argument is
not null and is a Bitset object that has
exactly the same set of subset set to true as this bit
set. That is, for every nonnegative int index
k,
((BitSet)obj).get(k) == this.get(k)must be true. The current sizes of the two bit sets are not compared.
Overrides the equals method of Object.
that_ - the object to compare with.
true if the objects are the same;
false otherwise.public void duplicate(java.lang.Object source_)
DrclObjsource_ object to this object.
he subclass must implement this method to realize DrclObj.clone().
duplicate in interface ObjectDuplicableduplicate in class DrclObjpublic java.lang.Object clone()
DrclObjDrclObj.duplicate(Object) to duplicate the content of this object to
the newly-created one.
This method uses getClass().newInstance() to create
new instance. Hence,
subclasses need to override this method only if the subclass is not
declared as public or does not have explicit no-argument constructor.
A subclass may override this method for performance reason.
clone in interface ObjectDuplicableclone in class DrclObjpublic java.lang.String toString()
toString method of Object.
Example:
BitSet bs_ = new BitSet();Now
bs_.toString() returns "-0-"
(empty set).
bs_.set(2);Now
bs_.toString() returns "2".
bs_.set(4); bs_.set(10);Now
bs_.toString() returns "2,4,10".
toString in class DrclObjpublic java.lang.String numberRepresentation()
public java.lang.String binaryRepresentation()
public java.lang.String binaryRepresentation(boolean skipLeadingZeros_)
skipLeadingZeros_ - if true, the leading zeros in the resulting
binary represenation is not printed.public java.lang.String binaryRepresentation(int length_)
length_ - expected number of binary characters.public java.lang.String hexRepresentation()
public java.lang.String hexRepresentation(boolean skipLeadingZeros_)
skipLeadingZeros_ - if true, the leading zeros in the resulting
binary represenation is not printed.public java.lang.String hexRepresentation(int length_)
length_ - expected number of hex characters.
|
J-Sim v1.2.1-p7 API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||