Package org.apache.wayang.core.util
Class Bitmask
- java.lang.Object
-
- org.apache.wayang.core.util.Bitmask
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Iterable<java.lang.Integer>
public class Bitmask extends java.lang.Object implements java.lang.Cloneable, java.lang.Iterable<java.lang.Integer>
A mutable bit-mask.
-
-
Field Summary
Fields Modifier and Type Field Description static Bitmask
EMPTY_BITMASK
An instance without any bits set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bitmask
and(Bitmask that)
Creates the new instance that merges this and the given one via logical AND.Bitmask
andInPlace(Bitmask that)
Accumulates the given instance to this one via logical AND.Bitmask
andNot(Bitmask that)
Creates the new instance that merges this and the given one via logical AND NOT.Bitmask
andNotInPlace(Bitmask that)
Accumulates the given instance to this one via logical AND NOT.int
cardinality()
Retrieves the number of set bits in this instance.boolean
equals(java.lang.Object o)
Bitmask
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.java.util.PrimitiveIterator.OfInt
iterator()
int
nextSetBit(int from)
Finds the next set bit, starting from a given index.Bitmask
or(Bitmask that)
Creates the new instance that merges this and the given one via logical OR.Bitmask
orInPlace(Bitmask that)
Accumulates the given instance to this one via logical OR.boolean
set(int index)
Sets the bit at the given index.java.util.Spliterator.OfInt
spliterator()
java.util.stream.IntStream
stream()
java.lang.String
toString()
-
-
-
Field Detail
-
EMPTY_BITMASK
public static Bitmask EMPTY_BITMASK
An instance without any bits set.
-
-
Constructor Detail
-
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
public Bitmask(Bitmask that)
Creates a new, copied instance.- Parameters:
that
- the instance to copy
-
Bitmask
public Bitmask(Bitmask that, int startCapacity)
Creates a new, copied instance.- Parameters:
that
- the instance to copystartCapacity
- the number of bits (starting from0
) that should already be held available
-
-
Method Detail
-
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
public Bitmask orInPlace(Bitmask that)
Accumulates the given instance to this one via logical OR.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
or
public Bitmask or(Bitmask that)
Creates the new instance that merges this and the given one via logical OR.- Parameters:
that
- the other instance- Returns:
- this merged instance
-
andInPlace
public Bitmask andInPlace(Bitmask that)
Accumulates the given instance to this one via logical AND.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
and
public Bitmask and(Bitmask that)
Creates the new instance that merges this and the given one via logical AND.- Parameters:
that
- the other instance- Returns:
- this merged instance
-
andNotInPlace
public Bitmask andNotInPlace(Bitmask that)
Accumulates the given instance to this one via logical AND NOT.- Parameters:
that
- that should be accumulated- Returns:
- this instance
-
andNot
public Bitmask andNot(Bitmask that)
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
public Bitmask flip(int fromIndex, int toIndex)
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
public boolean isSubmaskOf(Bitmask that)
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
public boolean isDisjointFrom(Bitmask that)
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
public java.util.PrimitiveIterator.OfInt iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.Integer>
-
spliterator
public java.util.Spliterator.OfInt spliterator()
- Specified by:
spliterator
in interfacejava.lang.Iterable<java.lang.Integer>
-
stream
public java.util.stream.IntStream stream()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-