Class BitString
- All Implemented Interfaces:
Serializable,Cloneable
BitString implements a vector of bits
;
much like BitSet... except that this implementation
actually works. Also, BitString has some groovy features
which BitSet doesn't; mostly related to efficient iteration
over true and false components, I think.
(That was true of the BitSet of Java 1.2. Since
Java 7, BitSet works, and searches backward as
well as forward.)
Each component of the BitString has a boolean value.
The bits of a BitString are indexed by non-negative
integers (that means they are zero-based, of course). Individual
indexed bits can be examined, set, or cleared. One
BitString may be used to modify the contents of another
BitString 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 current size, which is the number of bits of space currently in use by the bit set. Note that the size is related to the implementation of a bit set, so it may change with implementation. The length of a bit set related to the logical length of a bit set and is defined independently of implementation.
- Author:
- John Whaley <jwhaley@alum.mit.edu>
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBitString(int nbits) Deprecated.Creates an empty string with the specified size. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.Logically ANDs this bit set with the specified set of bits.voidclear(int bit) Deprecated.Clears a bit.voidclearAll()Deprecated.Clears all bits.voidclearUpTo(int bit) Deprecated.Clears all bits up to and including the given bit.clone()Deprecated.Clones the BitString.voidDeprecated.Copies the values of the bits in the specified set into this set.booleanDeprecated.Compares this object against the specified object.intfirstSet()Deprecated.Returns the first index in the bit string which is set, or -1 if there is no such index.intfirstSet(int where) Deprecated.Returns the first index greater thanwherein the bit string which is set, or -1 if there is no such index.booleanget(int bit) Deprecated.Gets a bit.inthashCode()Deprecated.Returns a hash code value for this bit string whose value depends only on which bits have been set within thisBitString.booleanintersectionEmpty(BitString other) Deprecated.Check if the intersection of the two sets is emptybooleanisZero()Deprecated.intlastSet()Deprecated.Returns the last index in the bit string which is set, or -1 if there is no such index.intlastSet(int where) Deprecated.Returns the last index less thanwherein the bit string which is set, or -1 if there is no such index.intlength()Deprecated.intDeprecated.intnumberOfOnes(int where) Deprecated.booleanDeprecated.Logically ORs this bit set with the specified set of bits.booleanDeprecated.Logically ORs this bit set with the specified set of bits.voidset(int bit) Deprecated.Sets a bit.voidsetAll()Deprecated.Sets all bits.voidsetUpTo(int bit) Deprecated.Sets all bits up to and including the given bit.intsize()Deprecated.Returns the number of bits of space actually in use by thisBitStringto represent bit values.toString()Deprecated.Converts the BitString to a String.booleanDeprecated.Logically XORs this bit set with the specified set of bits.
-
Constructor Details
-
BitString
public BitString(int nbits) Deprecated.Creates an empty string with the specified size.- Parameters:
nbits- the size of the string
-
-
Method Details
-
firstSet
public int firstSet()Deprecated.Returns the first index in the bit string which is set, or -1 if there is no such index. -
firstSet
public int firstSet(int where) Deprecated.Returns the first index greater thanwherein the bit string which is set, or -1 if there is no such index.- Parameters:
where- the starting point for the search. May be negative.
-
lastSet
public int lastSet(int where) Deprecated.Returns the last index less thanwherein the bit string which is set, or -1 if there is no such index.- Parameters:
where- the starting point for the search.
-
lastSet
public int lastSet()Deprecated.Returns the last index in the bit string which is set, or -1 if there is no such index. -
setAll
public void setAll()Deprecated.Sets all bits. -
setUpTo
public void setUpTo(int bit) Deprecated.Sets all bits up to and including the given bit.- Parameters:
bit- the bit to be set up to (zero-based)
-
set
public void set(int bit) Deprecated.Sets a bit.- Parameters:
bit- the bit to be set (zero-based)
-
clearAll
public void clearAll()Deprecated.Clears all bits. -
clearUpTo
public void clearUpTo(int bit) Deprecated.Clears all bits up to and including the given bit.- Parameters:
bit- the bit to be set up to (zero-based)
-
clear
public void clear(int bit) Deprecated.Clears a bit.- Parameters:
bit- the bit to be cleared (zero-based)
-
get
public boolean get(int bit) Deprecated.Gets a bit.- Parameters:
bit- the bit to be gotten (zero-based)
-
and
Deprecated.Logically ANDs this bit set with the specified set of bits. Returnstrueifthiswas modified in response to the operation.- Parameters:
set- the bit set to be ANDed with
-
or
Deprecated.Logically ORs this bit set with the specified set of bits. Returnstrueifthiswas modified in response to the operation.- Parameters:
set- the bit set to be ORed with
-
or_upTo
Deprecated.Logically ORs this bit set with the specified set of bits. Returnstrueifthiswas modified in response to the operation.- Parameters:
set- the bit set to be ORed with
-
xor
Deprecated.Logically XORs this bit set with the specified set of bits. Returnstrueifthiswas modified in response to the operation.- Parameters:
set- the bit set to be XORed with
-
intersectionEmpty
Deprecated.Check if the intersection of the two sets is empty- Parameters:
other- the set to check intersection with
-
copyBits
Deprecated.Copies the values of the bits in the specified set into this set.- Parameters:
set- the bit set to copy the bits from
-
hashCode
public int hashCode()Deprecated.Returns a hash code value for this bit string whose value depends only on which bits have been set within thisBitString. -
length
public int length()Deprecated. -
size
public int size()Deprecated.Returns the number of bits of space actually in use by thisBitStringto represent bit values. The maximum element in the set is the size - 1st element. The minimum element in the set is the zero'th element. -
equals
Deprecated.Compares this object against the specified object. -
isZero
public boolean isZero()Deprecated. -
numberOfOnes
public int numberOfOnes()Deprecated. -
numberOfOnes
public int numberOfOnes(int where) Deprecated. -
clone
Deprecated.Clones the BitString. -
toString
Deprecated.Converts the BitString to a String.
-
BitSet, which grows as needed:firstSet(where)isnextSetBit(where+1), andlastSet(where)ispreviousSetBit(where-1);setUpTo(bit)isset(0, bit+1), andclearUpTo(bit)isclear(0, bit+1);setAll()isset(0, n)for a sizen;clearAll()isclear();intersectionEmpty(o)is!intersects(o);isZero()isisEmpty();copyBits(o)isclear()thenor(o);numberOfOnes()iscardinality(), andnumberOfOnes(where)isget(0, where+1).cardinality();or_upTo(o, bit)isor(o.get(0, bit+1)).BitSet'sand(),or()andxor()do not return whether they changed the set: compare itscardinality()before and after anand()or anor().