APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class Bits

extends Object
Class Inheritance
Imports
java.util.Arrays

A bitset, without size limitation, allows comparison via bitwise operators to other bitfields.
Authors
mzechner, jshapcott

Field Summary

Modifier and TypeField and Description
pack-priv long[]

Constructor Summary

AccessConstructor and Description
public
Bits()

public
Bits(int
the initial size of the bit set
nbits
)

Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1.

public
Bits(Bits
bitset to cpy
bitsToCpy
)

Creates a bit set from another bit set

Method Summary

Modifier and TypeMethod and Description
public void
and(Bits
a bit set
other
)

Performs a logical AND of this target bit set with the argument bit set.

public void
andNot(Bits
a bit set
other
)

Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.

private void
checkCapacity(int len)

public void
clear(int
the index of the bit to clear
index
)

public void
clear()

Clears the entire bitset

public boolean

Returns:

boolean indicating whether this bit set is a super set of the specified set
containsAll
(Bits
a bit set
other
)

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.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public void
flip(int
the index of the bit to flip
index
)

public boolean
get(int
the index of the bit
index
)

Returns: whether the bit is set

public boolean

Returns:

whether the bit was set before invocation
getAndClear
(int
the index of the bit
index
)

Returns the bit at the given index and clears it in one go.

public boolean

Returns:

whether the bit was set before invocation
getAndSet
(int
the index of the bit
index
)

Returns the bit at the given index and sets it in one go.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

boolean indicating whether this bit set intersects the specified bit set
intersects
(Bits
a bit set
other
)

Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.

public boolean
isEmpty()

Returns: true if this bitset contains no bits that are set to true

public int

Returns:

the logical size of this bitset
length
()

Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one.

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.

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.

public boolean
notEmpty()

Returns: true if this bitset contains at least one bit set to true

public int
numBits()

Returns: the number of bits currently stored, not the highset set bit!

public void
or(Bits
a bit set
other
)

Performs a logical OR of this bit set with the bit set argument.

public void
set(int
the index of the bit to set
index
)

public void
xor(Bits other)

Performs a logical XOR of this bit set with the bit set argument.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

bitsback to summary
pack-priv long[] bits

Constructor Detail

Bitsback to summary
public Bits()
Bitsback to summary
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:int

the initial size of the bit set

Bitsback to summary
public Bits(Bits bitsToCpy)

Creates a bit set from another bit set

Parameters
bitsToCpy:Bits

bitset to cpy

Method Detail

andback to summary
public void and(Bits other)

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:Bits

a bit set

andNotback to summary
public void andNot(Bits other)

Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.

Parameters
other:Bits

a bit set

checkCapacityback to summary
private void checkCapacity(int len)
clearback to summary
public void clear(int index)
Parameters
index:int

the index of the bit to clear

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0
clearback to summary
public void clear()

Clears the entire bitset

containsAllback to summary
public boolean containsAll(Bits other)

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:Bits

a bit set

Returns:boolean

boolean indicating whether this bit set is a super set of the specified set

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
flipback to summary
public void flip(int index)
Parameters
index:int

the index of the bit to flip

getback to summary
public boolean get(int index)
Parameters
index:int

the index of the bit

Returns:boolean

whether the bit is set

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0
getAndClearback to summary
public boolean getAndClear(int index)

Returns the bit at the given index and clears it in one go.

Parameters
index:int

the index of the bit

Returns:boolean

whether the bit was set before invocation

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0
getAndSetback to summary
public boolean getAndSet(int index)

Returns the bit at the given index and sets it in one go.

Parameters
index:int

the index of the bit

Returns:boolean

whether the bit was set before invocation

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
intersectsback to summary
public boolean intersects(Bits other)

Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.

Parameters
other:Bits

a bit set

Returns:boolean

boolean indicating whether this bit set intersects the specified bit set

isEmptyback to summary
public boolean isEmpty()
Returns:boolean

true if this bitset contains no bits that are set to true

lengthback to summary
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:int

the logical size of this bitset

nextClearBitback to summary
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.

nextSetBitback to summary
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.

notEmptyback to summary
public boolean notEmpty()
Returns:boolean

true if this bitset contains at least one bit set to true

numBitsback to summary
public int numBits()
Returns:int

the number of bits currently stored, not the highset set bit!

orback to summary
public void or(Bits other)

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:Bits

a bit set

setback to summary
public void set(int index)
Parameters
index:int

the index of the bit to set

Exceptions
ArrayIndexOutOfBoundsException:
if index < 0
xorback to summary
public void xor(Bits other)

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.