Class SparseBitSet
- java.lang.Object
-
- com.zaxxer.sparsebits.SparseBitSet
-
- All Implemented Interfaces:
Serializable
,Cloneable
public class SparseBitSet extends Object implements Cloneable, Serializable
This class implements a set of bits that grows as needed. Each bit of the bit set represents aboolean
value. The values of aSparseBitSet
are indexed by non-negative integers. Individual indexed values may be examined, set, cleared, or modified by logical operations. OneSparseBitSet
or logical value may be used to modify the contents of (another)SparseBitSet
through logical AND, logical inclusive OR, logical exclusive OR, and And NOT operations over all or part of the bit sets.All values in a bit set initially have the value
false
.Every bit set has a current size, which is the number of bits of space nominally in use by the bit set from the first set bit to just after the last set bit. The length of the bit set effectively tells the position available after the last bit of the SparseBitSet.
The maximum cardinality of a
SparseBitSet
isInteger.MAX_VALUE
, which means the bits of aSparseBitSet
are labelled0
..Integer.MAX_VALUE − 1
. After the last set bit of aSparseBitSet
, any attempt to find a subsequent bit (nextSetBit()), will return an value of −1. If an attempt is made to use nextClearBit(), and all the bits are set from the starting position of the search to the bit labelledInteger.MAX_VALUE − 1
, then similarly −1 will be returned.Unless otherwise noted, passing a null parameter to any of the methods in a
SparseBitSet
will result in aNullPointerException
.A
SparseBitSet
is not safe for multi-threaded use without external synchronization.- Since:
- 1.6
- Version:
- 1.0, 2009-03-17
- Author:
- Bruce K. Haddon, Arthur van Hoff, Michael McCloskey, Martin Buchholz
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SparseBitSet.Statistics
These enumeration values are used as labels for the values in the String created by the statistics() method.
-
Constructor Summary
Constructors Constructor Description SparseBitSet()
Constructs an empty bit set with the default initial size.SparseBitSet(int nbits)
Creates a bit set whose initial size is large enough to efficiently represent bits with indices in the range0
through at leastnbits-1
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
and(int i, boolean value)
Performs a logical AND of the addressed target bit with the argument value.void
and(int i, int j, SparseBitSet b)
Performs a logical AND of this target bit set with the argument bit set within the given range of bits.void
and(SparseBitSet b)
Performs a logical AND of this target bit set with the argument bit set.static SparseBitSet
and(SparseBitSet a, SparseBitSet b)
Performs a logical AND of the two givenSparseBitSet
s.void
andNot(int i, boolean value)
Performs a logical AndNOT of the addressed target bit with the argument value.void
andNot(int i, int j, SparseBitSet b)
Performs a logical AndNOT of this target bit set with the argument bit set within the given range of bits.void
andNot(SparseBitSet b)
Performs a logical AndNOT of this target bit set with the argument bit set.static SparseBitSet
andNot(SparseBitSet a, SparseBitSet b)
Creates a bit set from thie firstSparseBitSet
whose corresponding bits are cleared by the set bits of the secondSparseBitSet
.int
cardinality()
Returns the number of bits set totrue
in thisSparseBitSet
.void
clear()
Sets all of the bits in thisSparseBitSet
tofalse
.void
clear(int i)
Sets the bit at the specified index tofalse
.void
clear(int i, int j)
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) tofalse
.SparseBitSet
clone()
Cloning thisSparseBitSet
produces a newSparseBitSet
that is equal() to it.boolean
equals(Object obj)
Compares this object against the specified object.void
flip(int i)
Sets the bit at the specified index to the complement of its current value.void
flip(int i, int j)
Sets each bit from the specifiedi
(inclusive) to the specifiedj
(exclusive) to the complement of its current value.boolean
get(int i)
Returns the value of the bit with the specified index.SparseBitSet
get(int i, int j)
Returns a newSparseBitSet
composed of bits from thisSparseBitSet
fromi
(inclusive) toj
(exclusive).int
hashCode()
Returns a hash code value for this bit set.boolean
intersects(int i, int j, SparseBitSet b)
Returns true if the specifiedSparseBitSet
has any bits within the given rangei
(inclusive) toj
(exclusive) set totrue
that are also set totrue
in the same range of thisSparseBitSet
.boolean
intersects(SparseBitSet b)
Returns true if the specifiedSparseBitSet
has any bits set totrue
that are also set totrue
in thisSparseBitSet
.boolean
isEmpty()
Returns true if thisSparseBitSet
contains no bits that are set totrue
.int
length()
Returns the "logical length" of thisSparseBitSet
: the index of the highest set bit in theSparseBitSet
plus one.int
nextClearBit(int i)
Returns the index of the first bit that is set tofalse
that occurs on or after the specified starting index.int
nextSetBit(int i)
Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index.void
or(int i, boolean value)
Performs a logical OR of the addressed target bit with the argument value.void
or(int i, int j, SparseBitSet b)
Performs a logical OR of the addressed target bit with the argument value within the given range.void
or(SparseBitSet b)
Performs a logical OR of this bit set with the bit set argument.static SparseBitSet
or(SparseBitSet a, SparseBitSet b)
Performs a logical OR of the two givenSparseBitSet
s.int
previousClearBit(int i)
Returns the index of the nearest bit that is set tofalse
that occurs on or before the specified starting index.int
previousSetBit(int i)
Returns the index of the nearest bit that is set totrue
that occurs on or before the specified starting index.void
set(int i)
Sets the bit at the specified index.void
set(int i, boolean value)
Sets the bit at the specified index to the specified value.void
set(int i, int j)
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) totrue
.void
set(int i, int j, boolean value)
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) to the specified value.int
size()
Returns the number of bits of space nominally in use by thisSparseBitSet
to represent bit values.String
statistics()
Convenience method for statistics if the individual results are not needed.String
statistics(String[] values)
Determine, and create a String with the bit set statistics.String
toString()
Returns a string representation of this bit set.void
toStringCompaction(boolean change)
If change istrue
, the current value of the toStringCompaction() value is made the default value for allSparseBitSet
s created from this point onward in this JVM.void
toStringCompaction(int count)
Sequences of set bits longer than this value are shown bytoString()
as a "sub-sequence," in the forma..b
.void
xor(int i, boolean value)
Performs a logical XOR of the addressed target bit with the argument value.void
xor(int i, int j, SparseBitSet b)
Performs a logical XOR of this bit set with the bit set argument within the given range.void
xor(SparseBitSet b)
Performs a logical XOR of this bit set with the bit set argument.static SparseBitSet
xor(SparseBitSet a, SparseBitSet b)
Performs a logical XOR of the two givenSparseBitSet
s.
-
-
-
Constructor Detail
-
SparseBitSet
public SparseBitSet()
Constructs an empty bit set with the default initial size. Initially all bits are effectivelyfalse
.- Since:
- 1.6
-
SparseBitSet
public SparseBitSet(int nbits) throws NegativeArraySizeException
Creates a bit set whose initial size is large enough to efficiently represent bits with indices in the range0
through at leastnbits-1
. Initially all bits are effectivelyfalse
.No guarantees are given for how large or small the actual object will be. The setting of bits above the given range is permitted (and will perhaps eventually cause resizing).
- Parameters:
nbits
- the initial provisional length of the SparseBitSet- Throws:
NegativeArraySizeException
- if the specified initial length is negative- Since:
- 1.6
- See Also:
SparseBitSet()
-
-
Method Detail
-
and
public void and(int i, boolean value) throws IndexOutOfBoundsException
Performs a logical AND of the addressed target bit with the argument value. This bit set is modified so that the addressed bit has the valuetrue
if and only if it both initially had the valuetrue
and the argument value is alsotrue
.- Parameters:
i
- a bit indexvalue
- a boolean value to AND with that bit- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
and
public void and(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
Performs a logical AND of this target bit set with the argument bit set within the given range of bits. Within the range, this bit set is modified so that each bit in it has the valuetrue
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument also had the valuetrue
. Outside the range, this set is not changed.- Parameters:
i
- index of the first bit to be included in the operationj
- index after the last bit to included in the operationb
- a SparseBitSet- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
and
public void and(SparseBitSet b)
Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the valuetrue
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument also had the valuetrue
.- Parameters:
b
- a SparseBitSet- Since:
- 1.6
-
and
public static SparseBitSet and(SparseBitSet a, SparseBitSet b)
Performs a logical AND of the two givenSparseBitSet
s. The returnedSparseBitSet
is created so that each bit in it has the valuetrue
if and only if both the given sets initially had the corresponding bitstrue
, otherwisefalse
.- Parameters:
a
- a SparseBitSetb
- another SparseBitSet- Returns:
- a new SparseBitSet representing the AND of the two sets
- Since:
- 1.6
-
andNot
public void andNot(int i, boolean value)
Performs a logical AndNOT of the addressed target bit with the argument value. This bit set is modified so that the addressed bit has the valuetrue
if and only if it both initially had the valuetrue
and the argument value isfalse
.- Parameters:
i
- a bit indexvalue
- a boolean value to AndNOT with that bit- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
andNot
public void andNot(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
Performs a logical AndNOT of this target bit set with the argument bit set within the given range of bits. Within the range, this bit set is modified so that each bit in it has the valuetrue
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument has the valuefalse
. Outside the range, this set is not changed.- Parameters:
i
- index of the first bit to be included in the operationj
- index after the last bit to included in the operationb
- the SparseBitSet with which to mask this SparseBitSet- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
andNot
public void andNot(SparseBitSet b)
Performs a logical AndNOT of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the valuetrue
if and only if it both initially had the valuetrue
and the corresponding bit in the bit set argument has the valuefalse
.- Parameters:
b
- the SparseBitSet with which to mask this SparseBitSet- Since:
- 1.6
-
andNot
public static SparseBitSet andNot(SparseBitSet a, SparseBitSet b)
Creates a bit set from thie firstSparseBitSet
whose corresponding bits are cleared by the set bits of the secondSparseBitSet
. The resulting bit set is created so that a bit in it has the valuetrue
if and only if the corresponding bit in theSparseBitSet
of the first is set, and that same corresponding bit is not set in theSparseBitSet
of the second argument.- Parameters:
a
- a SparseBitSetb
- another SparseBitSet- Returns:
- a new SparseBitSet representing the AndNOT of the two sets
- Since:
- 1.6
-
cardinality
public int cardinality()
Returns the number of bits set totrue
in thisSparseBitSet
.- Returns:
- the number of bits set to true in this SparseBitSet
- Since:
- 1.6
-
clear
public void clear(int i)
Sets the bit at the specified index tofalse
.- Parameters:
i
- a bit index.- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE.- Since:
- 1.6
-
clear
public void clear(int i, int j) throws IndexOutOfBoundsException
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) tofalse
.- Parameters:
i
- index of the first bit to be clearedj
- index after the last bit to be cleared- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
clear
public void clear()
Sets all of the bits in thisSparseBitSet
tofalse
.- Since:
- 1.6
-
clone
public SparseBitSet clone()
Cloning thisSparseBitSet
produces a newSparseBitSet
that is equal() to it. The clone of the bit set is another bit set that has exactly the same bits set totrue
as this bit set.Note: the actual space allocated to the clone tries to minimise the actual amount of storage allocated to hold the bits, while still trying to keep access to the bits being a rapid as possible. Since the space allocated to a
SparseBitSet
is not normally decreased, replacing a bit set by its clone may be a way of both managing memory consumption and improving the rapidity of access.- Returns:
- a clone of this SparseBitSet
- Since:
- 1.6
-
equals
public boolean equals(Object obj)
Compares this object against the specified object. The result istrue
if and only if the argument is notnull
and is aSparseBitSet
object that has exactly the same bits set totrue
as this bit set. That is, for every nonnegativei
indexing a bit in the set,((SparseBitSet)obj).get(i) == this.get(i)
must be true.
-
flip
public void flip(int i)
Sets the bit at the specified index to the complement of its current value.- Parameters:
i
- the index of the bit to flip- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
flip
public void flip(int i, int j) throws IndexOutOfBoundsException
Sets each bit from the specifiedi
(inclusive) to the specifiedj
(exclusive) to the complement of its current value.- Parameters:
i
- index of the first bit to flipj
- index after the last bit to flip- Throws:
IndexOutOfBoundsException
- ifi
is negative or is equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
get
public boolean get(int i)
Returns the value of the bit with the specified index. The value istrue
if the bit with the indexi
is currently set in thisSparseBitSet
; otherwise, the result isfalse
.- Parameters:
i
- the bit index- Returns:
- the boolean value of the bit with the specified index.
- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
get
public SparseBitSet get(int i, int j) throws IndexOutOfBoundsException
Returns a newSparseBitSet
composed of bits from thisSparseBitSet
fromi
(inclusive) toj
(exclusive).- Parameters:
i
- index of the first bit to includej
- index after the last bit to include- Returns:
- a new SparseBitSet from a range of this SparseBitSet
- Throws:
IndexOutOfBoundsException
- ifi
is negative or is equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
hashCode
public int hashCode()
Returns a hash code value for this bit set. The hash code depends only on which bits have been set within thisSparseBitSet
. The algorithm used to compute it may be described as follows.Suppose the bits in the
SparseBitSet
were to be stored in an array oflong
integers called, say,bits
, in such a manner that biti
is set in theSparseBitSet
(for nonnegative values ofi
) if and only if the expression((i>>6) < bits.length) && ((bits[i>>6] & (1L << (bit & 0x3F))) != 0)
is true. Then the following definition of thehashCode
method would be a correct implementation of the actual algorithm:public int hashCode() { long hash = 1234L; for( int i = bits.length; --i >= 0; ) hash ^= bits[i] * (i + 1); return (int)((h >> 32) ^ h); }
Note that the hash code values change if the set of bits is altered.- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this bit set
- Since:
- 1.6
- See Also:
Object.equals(Object)
,Hashtable
-
intersects
public boolean intersects(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
Returns true if the specifiedSparseBitSet
has any bits within the given rangei
(inclusive) toj
(exclusive) set totrue
that are also set totrue
in the same range of thisSparseBitSet
.- Parameters:
i
- index of the first bit to includej
- index after the last bit to includeb
- the SparseBitSet with which to intersect- Returns:
- the boolean indicating whether this SparseBitSet intersects the specified SparseBitSet
- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
intersects
public boolean intersects(SparseBitSet b)
Returns true if the specifiedSparseBitSet
has any bits set totrue
that are also set totrue
in thisSparseBitSet
.- Parameters:
b
- a SparseBitSet with which to intersect- Returns:
- boolean indicating whether this SparseBitSet intersects the specified SparseBitSet
- Since:
- 1.6
-
isEmpty
public boolean isEmpty()
Returns true if thisSparseBitSet
contains no bits that are set totrue
.- Returns:
- the boolean indicating whether this SparseBitSet is empty
- Since:
- 1.6
-
length
public int length()
Returns the "logical length" of thisSparseBitSet
: the index of the highest set bit in theSparseBitSet
plus one. Returns zero if theSparseBitSet
contains no set bits.- Returns:
- the logical length of this SparseBitSet
- Since:
- 1.6
-
nextClearBit
public int nextClearBit(int i)
Returns the index of the first bit that is set tofalse
that occurs on or after the specified starting index.- Parameters:
i
- the index to start checking from (inclusive)- Returns:
- the index of the next clear bit, or -1 if there is no such bit
- Throws:
IndexOutOfBoundsException
- if the specified index is negative- Since:
- 1.6
-
nextSetBit
public int nextSetBit(int i)
Returns the index of the first bit that is set totrue
that occurs on or after the specified starting index. If no such it exists then -1 is returned.To iterate over the
true
bits in aSparseBitSet sbs
, use the following loop:for( int i = sbbits.nextSetBit(0); i >= 0; i = sbbits.nextSetBit(i+1) ) { // operate on index i here }
- Parameters:
i
- the index to start checking from (inclusive)- Returns:
- the index of the next set bit
- Throws:
IndexOutOfBoundsException
- if the specified index is negative- Since:
- 1.6
-
previousClearBit
public int previousClearBit(int i)
Returns the index of the nearest bit that is set tofalse
that occurs on or before the specified starting index. If no such bit exists, or if-1
is given as the starting index, then-1
is returned.- Parameters:
i
- the index to start checking from (inclusive)- Returns:
- the index of the previous clear bit, or
-1
if there is no such bit - Throws:
IndexOutOfBoundsException
- if the specified index is less than-1
- Since:
- 1.2
- See Also:
BitSet.previousClearBit(int)
-
previousSetBit
public int previousSetBit(int i)
Returns the index of the nearest bit that is set totrue
that occurs on or before the specified starting index. If no such bit exists, or if-1
is given as the starting index, then-1
is returned.- Parameters:
i
- the index to start checking from (inclusive)- Returns:
- the index of the previous set bit, or
-1
if there is no such bit - Throws:
IndexOutOfBoundsException
- if the specified index is less than-1
- Since:
- 1.2
- See Also:
BitSet.previousSetBit(int)
-
or
public void or(int i, boolean value)
Performs a logical OR of the addressed target bit with the argument value. This bit set is modified so that the addressed bit has the valuetrue
if and only if it both initially had the valuetrue
or the argument value istrue
.- Parameters:
i
- a bit indexvalue
- a boolean value to OR with that bit- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
or
public void or(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
Performs a logical OR of the addressed target bit with the argument value within the given range. This bit set is modified so that within the range a bit in it has the valuetrue
if and only if it either already had the valuetrue
or the corresponding bit in the bit set argument has the valuetrue
. Outside the range this set is not changed.- Parameters:
i
- index of the first bit to be included in the operationj
- index after the last bit to included in the operationb
- the SparseBitSet with which to perform the OR operation with this SparseBitSet- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
or
public void or(SparseBitSet b)
Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the valuetrue
if and only if it either already had the valuetrue
or the corresponding bit in the bit set argument has the valuetrue
.- Parameters:
b
- the SparseBitSet with which to perform the OR operation with this SparseBitSet- Since:
- 1.6
-
or
public static SparseBitSet or(SparseBitSet a, SparseBitSet b)
Performs a logical OR of the two givenSparseBitSet
s. The returnedSparseBitSet
is created so that a bit in it has the valuetrue
if and only if it either had the valuetrue
in the set given by the first arguemetn or had the valuetrue
in the second argument, otherwisefalse
.- Parameters:
a
- a SparseBitSetb
- another SparseBitSet- Returns:
- new SparseBitSet representing the OR of the two sets
- Since:
- 1.6
-
set
public void set(int i)
Sets the bit at the specified index.- Parameters:
i
- a bit index- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
set
public void set(int i, boolean value)
Sets the bit at the specified index to the specified value.- Parameters:
i
- a bit indexvalue
- a boolean value to set- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
-
set
public void set(int i, int j) throws IndexOutOfBoundsException
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) totrue
.- Parameters:
i
- index of the first bit to be setj
- index after the last bit to be se- Throws:
IndexOutOfBoundsException
- ifi
is negative or is equal to Integer.MAX_INT, orj
is negative, ori
is larger thanj
.- Since:
- 1.6
-
set
public void set(int i, int j, boolean value)
Sets the bits from the specifiedi
(inclusive) to the specifiedj
(exclusive) to the specified value.- Parameters:
i
- index of the first bit to be setj
- index after the last bit to be setvalue
- to which to set the selected bits- Throws:
IndexOutOfBoundsException
- ifi
is negative or is equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
-
size
public int size()
Returns the number of bits of space nominally in use by thisSparseBitSet
to represent bit values. The count of bits in the set is the (label of the last set bit) + 1 - (the label of the first set bit).- Returns:
- the number of bits (true and false) nominally in this bit set at this moment
- Since:
- 1.6
-
statistics
public String statistics()
Convenience method for statistics if the individual results are not needed.- Returns:
- a String detailing the statistics of the bit set
- Since:
- 1.6
- See Also:
statistics(String[])
-
statistics
public String statistics(String[] values)
Determine, and create a String with the bit set statistics. The statistics include: Size, Length, Cardinality, Total words (i.e., the total number of 64-bit "words"), Set array length (i.e., the number of references that can be held by the top level array, Level2 areas in use, Level3 blocks in use,, Level2 pool size, Level3 pool size, and the Compaction count.This method is intended for diagnostic use (as it is relatively expensive in time), but can be useful in understanding an application's use of a
SparseBitSet
.- Parameters:
values
- an array for the individual results (if not null)- Returns:
- a String detailing the statistics of the bit set
- Since:
- 1.6
-
toString
public String toString()
Returns a string representation of this bit set. For every index for which thisSparseBitSet
contains a bit in the set state, the decimal representation of that index is included in the result. Such indices are listed in order from lowest to highest. If there is a subsequence of set bits longer than the value given by toStringCompaction, the subsequence is represented by the value for the first and the last values, with ".." between them. The individual bits, or the representation of sub-sequences are separated by ", " (a comma and a space) and surrounded by braces, resulting in a compact string showing (a variant of) the usual mathematical notation for a set of integers.
Example (with the default value of 2 for subsequences):SparseBitSet drPepper = new SparseBitSet();
NowdrPepper.toString()
returns "{}
".
drPepper.set(2);
NowdrPepper.toString()
returns "{2}
".
drPepper.set(3, 4); drPepper.set(10);
NowdrPepper.toString()
returns "{2..4, 10}
".
This method is intended for diagnostic use (as it is relatively expensive in time), but can be useful in interpreting problems in an application's use of aSparseBitSet
.- Overrides:
toString
in classObject
- Returns:
- a String representation of this SparseBitSet
- Since:
- 1.6
- See Also:
toStringCompaction(int length)
-
toStringCompaction
public void toStringCompaction(int count)
Sequences of set bits longer than this value are shown bytoString()
as a "sub-sequence," in the forma..b
. Setting this value to zero causes each set bit to be listed individually. The default default value is 2 (which means sequences of three or more bits set are shown as a subsequence, and all other set bits are listed individually).Note: this value will be passed to
SparseBitSet
s that may be created within or as a result of the operations on this bit set, or, for static methods, from the value belonging to the first parameter.- Parameters:
count
- the maximum count of a run of bits that are shown as individual entries in atoString
() conversion. If 0, all bits are shown individually.- Since:
- 1.6
- See Also:
toString()
-
toStringCompaction
public void toStringCompaction(boolean change)
If change istrue
, the current value of the toStringCompaction() value is made the default value for allSparseBitSet
s created from this point onward in this JVM.- Parameters:
change
- if true, change the default value- Since:
- 1.6
-
xor
public void xor(int i, boolean value)
Performs a logical XOR of the addressed target bit with the argument value. This bit set is modified so that the addressed bit has the valuetrue
if and only one of the following statements holds:- The addressed bit initially had the value
true
, and the value of the argument isfalse
. - The bit initially had the value
false
, and the value of the argument istrue
.
- Parameters:
i
- a bit indexvalue
- a boolean value to XOR with that bit- Throws:
IndexOutOfBoundsException
- if the specified index is negative or equal to Integer.MAX_VALUE- Since:
- 1.6
- The addressed bit initially had the value
-
xor
public void xor(int i, int j, SparseBitSet b) throws IndexOutOfBoundsException
Performs a logical XOR of this bit set with the bit set argument within the given range. This resulting bit set is computed so that a bit within the range in it has the valuetrue
if and only if one of the following statements holds:- The bit initially had the value
true
, and the corresponding bit in the argument set has the valuefalse
. - The bit initially had the value
false
, and the corresponding bit in the argument set has the valuetrue
.
- Parameters:
i
- index of the first bit to be included in the operationj
- index after the last bit to included in the operationb
- the SparseBitSet with which to perform the XOR operation with this SparseBitSet- Throws:
IndexOutOfBoundsException
- ifi
is negative or equal to Integer.MAX_VALUE, orj
is negative, ori
is larger thanj
- Since:
- 1.6
- The bit initially had the value
-
xor
public void xor(SparseBitSet b)
Performs a logical XOR of this bit set with the bit set argument. This resulting bit set is computed so that a bit in it has the valuetrue
if and only if one of the following statements holds:- The bit initially had the value
true
, and the corresponding bit in the argument set has the valuefalse
. - The bit initially had the value
false
, and the corresponding bit in the argument set has the valuetrue
.
- Parameters:
b
- the SparseBitSet with which to perform the XOR operation with thisSparseBitSet- Since:
- 1.6
- The bit initially had the value
-
xor
public static SparseBitSet xor(SparseBitSet a, SparseBitSet b)
Performs a logical XOR of the two givenSparseBitSet
s. The resulting bit set is created so that a bit in it has the valuetrue
if and only if one of the following statements holds:- A bit in the first argument has the value
true
, and the corresponding bit in the second argument has the valuefalse
. - A bit in the first argument has the value
false
, and the corresponding bit in the second argument has the valuetrue
.
- Parameters:
a
- a SparseBitSetb
- another SparseBitSet- Returns:
- a new SparseBitSet representing the XOR of the two sets
- Since:
- 1.6
- A bit in the first argument has the value
-
-