Package org.apache.wayang.core.util
Class Bitmask
java.lang.Object
org.apache.wayang.core.util.Bitmask
A mutable bit-mask.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates the new instance that merges this and the given one via logical AND.andInPlace
(Bitmask that) Accumulates the given instance to this one via logical AND.Creates the new instance that merges this and the given one via logical AND NOT.andNotInPlace
(Bitmask that) Accumulates the given instance to this one via logical AND NOT.int
Retrieves the number of set bits in this instance.boolean
flip
(int fromIndex, int toIndex) Flips all bits in the given rangeboolean
get
(int index) Gets the bit at the given index.int
hashCode()
boolean
isDisjointFrom
(Bitmask that) Checks whether all bits set in this instance are not set in the given instance.boolean
isEmpty()
Tells whether this instance is empty.boolean
isSubmaskOf
(Bitmask that) Checks whether all bits set in this instance are also set in the given instance.iterator()
int
nextSetBit
(int from) Finds the next set bit, starting from a given index.Creates the new instance that merges this and the given one via logical OR.Accumulates the given instance to this one via logical OR.boolean
set
(int index) Sets the bit at the given index.stream()
toString()
-
Field Details
-
EMPTY_BITMASK
An instance without any bits set.
-
-
Constructor Details
-
Bitmask
public Bitmask()Creates a new instance. -
Bitmask
public Bitmask(int startCapacity) Creates a new instance.- Parameters:
startCapacity
- the number of bits (starting from0
) that should already be held available
-
Bitmask
Creates a new, copied instance.- Parameters:
that
- the instance to copy
-
Bitmask
Creates a new, copied instance.- Parameters:
that
- the instance to copystartCapacity
- the number of bits (starting from0
) that should already be held available
-
-
Method Details
-
set
public boolean set(int index) Sets the bit at the given index.- Parameters:
index
- where the bit should be set- Returns:
- whether this instance was changed
-
get
public boolean get(int index) Gets the bit at the given index.- Parameters:
index
- where the bit should be set- Returns:
- whether the bit in question is set
-
cardinality
public int cardinality()Retrieves the number of set bits in this instance.- Returns:
- the number of set bits
-
isEmpty
public boolean isEmpty()Tells whether this instance is empty.- Returns:
- whether this instance is empty
-
orInPlace
Accumulates the given instance to this one via logical OR.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
or
Creates the new instance that merges this and the given one via logical OR.- Parameters:
that
- the other instance- Returns:
- this merged instance
-
andInPlace
Accumulates the given instance to this one via logical AND.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
and
Creates the new instance that merges this and the given one via logical AND.- Parameters:
that
- the other instance- Returns:
- this merged instance
-
andNotInPlace
Accumulates the given instance to this one via logical AND NOT.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
andNot
Creates the new instance that merges this and the given one via logical AND NOT.- Parameters:
that
- the other instance- Returns:
- this merged instance
-
flip
Flips all bits in the given range- Parameters:
fromIndex
- inclusive start index of the rangetoIndex
- exclusive end index of the range- Returns:
- this instance
-
isSubmaskOf
Checks whether all bits set in this instance are also set in the given instance.- Parameters:
that
- the potential supermask- Returns:
- whether this is a submask
-
isDisjointFrom
Checks whether all bits set in this instance are not set in the given instance.- Parameters:
that
- the potential disjoint instance- Returns:
- whether the instances are disjoint
-
nextSetBit
public int nextSetBit(int from) Finds the next set bit, starting from a given index.- Parameters:
from
- index from that the search starts- Returns:
- the index of the set next bit or
-1
if there is no next set bit
-
iterator
-
spliterator
- Specified by:
spliterator
in interfaceIterable<Integer>
-
stream
-
toString
-
equals
-
hashCode
public int hashCode()
-