Class Bitmask

java.lang.Object
org.apache.wayang.core.util.Bitmask
All Implemented Interfaces:
Cloneable, Iterable<Integer>

public class Bitmask extends Object implements Cloneable, Iterable<Integer>
A mutable bit-mask.
  • Field Details

    • EMPTY_BITMASK

      public static Bitmask 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 from 0) 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 copy
      startCapacity - the number of bits (starting from 0) 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

      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 range
      toIndex - 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 PrimitiveIterator.OfInt iterator()
      Specified by:
      iterator in interface Iterable<Integer>
    • spliterator

      public Spliterator.OfInt spliterator()
      Specified by:
      spliterator in interface Iterable<Integer>
    • stream

      public IntStream stream()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object