Package org.jgroups.util
Class FixedSizeBitSet
java.lang.Object
org.jgroups.util.FixedSizeBitSet
Class copied from
BitSet. Changes are that the FixedSizeBitSet doesn't expand, so access to it
doesn't need to be synchronized, plus we only need a few methods so most methods of the old class have been removed.- Author:
- Bela Ban
-
Constructor Summary
ConstructorsConstructorDescriptionFixedSizeBitSet(int size) Creates a bit set whose initial size is the range0throughsize-1. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bits set to true in this bit setvoidclear(int index) Sets the bit specified by the index tofalse.booleanget(int index) Returns the value of the bit with the specified index.intnextClearBit(int fromIndex) Returns the index of the first bit that is set tofalsethat occurs on or after the specified starting index.intnextSetBit(int fromIndex) Returns the index of the first bit that is set totruethat occurs on or after the specified starting index.voidset(int index) Sets the bit at the specified index totrue.intsize()toString()Returns a string representation of this bit set.
-
Constructor Details
-
FixedSizeBitSet
public FixedSizeBitSet(int size) Creates a bit set whose initial size is the range0throughsize-1. All bits are initiallyfalse.- Parameters:
size- the initial size of the bit set (in bits).- Throws:
NegativeArraySizeException- if the specified initial size is negative
-
-
Method Details
-
set
public void set(int index) Sets the bit at the specified index totrue.- Parameters:
index- a bit index.- Throws:
IndexOutOfBoundsException- if the specified index is negative.
-
clear
public void clear(int index) Sets the bit specified by the index tofalse.- Parameters:
index- the index of the bit to be cleared.- Throws:
IndexOutOfBoundsException- if the specified index is negative.
-
get
public boolean get(int index) Returns the value of the bit with the specified index. The value istrueif the bit with the indexindexis currently set in this bit set; otherwise, the result isfalse.- Parameters:
index- the bit index.- Returns:
- the value of the bit with the specified index.
- Throws:
IndexOutOfBoundsException- if the specified index is negative.
-
nextSetBit
public int nextSetBit(int fromIndex) Returns the index of the first bit that is set totruethat occurs on or after the specified starting index. If no such bit exists then -1 is returned. To iterate over thetruebits in aBitSet, use the following loop:for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) { // operate on index i here }- Parameters:
fromIndex- the index to start checking from (inclusive).- Returns:
- the index of the next set bit.
- Throws:
IndexOutOfBoundsException- if the specified index is negative.
-
nextClearBit
public int nextClearBit(int fromIndex) Returns the index of the first bit that is set tofalsethat occurs on or after the specified starting index.- Parameters:
fromIndex- the index to start checking from (inclusive).- Returns:
- the index of the next clear bit.
- Throws:
IndexOutOfBoundsException- if the specified index is negative.
-
cardinality
public int cardinality()Returns the number of bits set to true in this bit set- Returns:
- the number of bits set to true in this bit set
-
size
public int size() -
toString
Returns a string representation of this bit set. For every index for which thisBitSetcontains 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, separated by ", " (a comma and a space) and surrounded by braces, resulting in the usual mathematical notation for a set of integers.Overrides the
toStringmethod ofObject.Example:
BitSet drPepper = new BitSet();
NowdrPepper.toString()returns "{}".drPepper.set(2);
NowdrPepper.toString()returns "{2}".drPepper.set(4); drPepper.set(10);
NowdrPepper.toString()returns "{2, 4, 10}".
-