Class Bits
java.lang.Object
gaiasky.util.Bits
- Direct Known Subclasses:
ComponentTypes
Implements an arbitrarily large array of bits using an array of long integers.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPerforms a logical AND of this target bit set with the argument bit set.Clears all the bits in this bit set whose corresponding bit is set in the specified bit set.voidclear()Clears the entire bitsetvoidclear(int index) intbooleancontainsAll(Bits other) Returns true if this bit set is a super set of the specified set, i.e.copy()static Bitsempty()static Bitsempty(int nBits) booleanvoidflip(int index) static Bitsfrom(long mask) booleanget(int index) booleangetAndClear(int index) Returns the bit at the given index and clears it in one go.booleangetAndSet(int index) Returns the bit at the given index and sets it in one go.booleanhas(int index) inthashCode()static Bitsindices(int... idx) booleanintersects(Bits other) Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.booleanis(int index) booleanisEmpty()intlength()Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one.intnextClearBit(int fromIndex) Returns the index of the first bit that is set to false that occurs on or after the specified starting index.intnextSetBit(int fromIndex) Returns the index of the first bit that is set to true that occurs on or after the specified starting index.booleannotEmpty()intnumBits()Performs a logical OR of this bit set with the bit set argument.voidset(int index) voidsetMask(long mask) toString()Performs a logical XOR of this bit set with the bit set argument.
-
Field Details
-
DEFAULT_LENGTH
public static int DEFAULT_LENGTH
-
-
Constructor Details
-
Bits
public Bits() -
Bits
public Bits(int nBits) Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nBits-1.- Parameters:
nBits- the initial size of the bit set
-
-
Method Details
-
empty
-
empty
-
from
-
indices
-
has
public boolean has(int index) -
is
public boolean is(int index) -
get
public boolean get(int index) - Parameters:
index- the index of the bit- Returns:
- whether the bit is set
- Throws:
ArrayIndexOutOfBoundsException- if index < 0
-
getAndClear
public boolean getAndClear(int index) Returns the bit at the given index and clears it in one go.- Parameters:
index- the index of the bit- Returns:
- whether the bit was set before invocation
- Throws:
ArrayIndexOutOfBoundsException- if index < 0
-
getAndSet
public boolean getAndSet(int index) Returns the bit at the given index and sets it in one go.- Parameters:
index- the index of the bit- Returns:
- whether the bit was set before invocation
- Throws:
ArrayIndexOutOfBoundsException- if index < 0
-
set
public void set(int index) - Parameters:
index- the index of the bit to set- Throws:
ArrayIndexOutOfBoundsException- if index < 0
-
setMask
public void setMask(long mask) -
flip
public void flip(int index) - Parameters:
index- the index of the bit to flip
-
clear
public void clear(int index) - Parameters:
index- the index of the bit to clear- Throws:
ArrayIndexOutOfBoundsException- if index < 0
-
clear
public void clear()Clears the entire bitset -
numBits
public int numBits()- Returns:
- the number of bits currently stored, not the highset set bit!
-
length
public int length()Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one. Returns zero if the bitset contains no set bits.- Returns:
- the logical size of this bitset
-
notEmpty
public boolean notEmpty()- Returns:
- true if this bitset contains at least one bit set to true
-
isEmpty
public boolean isEmpty()- Returns:
- true if this bitset contains no bits that are set to true
-
nextSetBit
public int nextSetBit(int fromIndex) Returns the index of the first bit that is set to true that occurs on or after the specified starting index. If no such bit exists then -1 is returned. -
nextClearBit
public int nextClearBit(int fromIndex) Returns the index of the first bit that is set to false that occurs on or after the specified starting index. -
and
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 value 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.- Parameters:
other- a bit set
-
andNot
-
or
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 value 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.- Parameters:
other- a bit set
-
xor
Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:- The bit initially has the value true, and the corresponding bit in the argument has the value false.
- The bit initially has the value false, and the corresponding bit in the argument has the value true.
- Parameters:
other- The other instance.
-
intersects
Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.- Parameters:
other- a bit set- Returns:
- boolean indicating whether this bit set intersects the specified bit set
-
containsAll
Returns true if this bit set is a super set of the specified set, i.e. it has all bits set to true that are also set to true in the specified BitSet.- Parameters:
other- a bit set- Returns:
- boolean indicating whether this bit set is a super set of the specified set
-
hashCode
-
equals
-
copy
-
compareTo
-
toString
-