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 BitmaskEMPTY_BITMASKAn instance without any bits set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bitmaskand(Bitmask that)Creates the new instance that merges this and the given one via logical AND.BitmaskandInPlace(Bitmask that)Accumulates the given instance to this one via logical AND.BitmaskandNot(Bitmask that)Creates the new instance that merges this and the given one via logical AND NOT.BitmaskandNotInPlace(Bitmask that)Accumulates the given instance to this one via logical AND NOT.intcardinality()Retrieves the number of set bits in this instance.booleanequals(java.lang.Object o)Bitmaskflip(int fromIndex, int toIndex)Flips all bits in the given rangebooleanget(int index)Gets the bit at the given index.inthashCode()booleanisDisjointFrom(Bitmask that)Checks whether all bits set in this instance are not set in the given instance.booleanisEmpty()Tells whether this instance is empty.booleanisSubmaskOf(Bitmask that)Checks whether all bits set in this instance are also set in the given instance.java.util.PrimitiveIterator.OfIntiterator()intnextSetBit(int from)Finds the next set bit, starting from a given index.Bitmaskor(Bitmask that)Creates the new instance that merges this and the given one via logical OR.BitmaskorInPlace(Bitmask that)Accumulates the given instance to this one via logical OR.booleanset(int index)Sets the bit at the given index.java.util.Spliterator.OfIntspliterator()java.util.stream.IntStreamstream()java.lang.StringtoString()
-
-
-
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
-1if there is no next set bit
-
iterator
public java.util.PrimitiveIterator.OfInt iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Integer>
-
spliterator
public java.util.Spliterator.OfInt spliterator()
- Specified by:
spliteratorin interfacejava.lang.Iterable<java.lang.Integer>
-
stream
public java.util.stream.IntStream stream()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-