Package gaiasky.util

Class Bits

java.lang.Object
gaiasky.util.Bits

public class Bits extends Object
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    static int
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
     
    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.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    and(Bits other)
    Performs a logical AND of this target bit set with the argument bit set.
    andNot(Bits other)
    Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.
    void
    Clears the entire bitset
    void
    clear(int index)
     
    int
    compareTo(Bits other)
     
    boolean
    Returns true if this bit set is a super set of the specified set, i.e.
     
    static Bits
     
    static Bits
    empty(int nBits)
     
    boolean
     
    void
    flip(int index)
     
    static Bits
    from(long mask)
     
    boolean
    get(int index)
     
    boolean
    getAndClear(int index)
    Returns the bit at the given index and clears it in one go.
    boolean
    getAndSet(int index)
    Returns the bit at the given index and sets it in one go.
    boolean
    has(int index)
     
    int
     
    static Bits
    indices(int... idx)
     
    boolean
    Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.
    boolean
    is(int index)
     
    boolean
     
    int
    Returns the "logical size" of this bitset: the index of the highest set bit in the bitset plus one.
    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.
    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.
    boolean
     
    int
     
    or(Bits other)
    Performs a logical OR of this bit set with the bit set argument.
    void
    set(int index)
     
    void
    setMask(long mask)
     
     
    xor(Bits other)
    Performs a logical XOR of this bit set with the bit set argument.

    Methods inherited from class java.lang.Object Link icon

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details Link icon

    • DEFAULT_LENGTH Link icon

      public static int DEFAULT_LENGTH
  • Constructor Details Link icon

    • Bits Link icon

      public Bits()
    • Bits Link icon

      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 - the initial size of the bit set
  • Method Details Link icon

    • empty Link icon

      public static Bits empty()
    • empty Link icon

      public static Bits empty(int nBits)
    • from Link icon

      public static Bits from(long mask)
    • indices Link icon

      public static Bits indices(int... idx)
    • has Link icon

      public boolean has(int index)
    • is Link icon

      public boolean is(int index)
    • get Link icon

      public boolean get(int index)
      Parameters:
      index - the index of the bit
      Returns:
      whether the bit is set
      Throws:
      ArrayIndexOutOfBoundsException - if index invalid input: '<' 0
    • getAndClear Link icon

      public boolean getAndClear(int index)
      Returns the bit at the given index and clears it in one go.
      Parameters:
      index - the index of the bit
      Returns:
      whether the bit was set before invocation
      Throws:
      ArrayIndexOutOfBoundsException - if index invalid input: '<' 0
    • getAndSet Link icon

      public boolean getAndSet(int index)
      Returns the bit at the given index and sets it in one go.
      Parameters:
      index - the index of the bit
      Returns:
      whether the bit was set before invocation
      Throws:
      ArrayIndexOutOfBoundsException - if index invalid input: '<' 0
    • set Link icon

      public void set(int index)
      Parameters:
      index - the index of the bit to set
      Throws:
      ArrayIndexOutOfBoundsException - if index invalid input: '<' 0
    • setMask Link icon

      public void setMask(long mask)
    • flip Link icon

      public void flip(int index)
      Parameters:
      index - the index of the bit to flip
    • clear Link icon

      public void clear(int index)
      Parameters:
      index - the index of the bit to clear
      Throws:
      ArrayIndexOutOfBoundsException - if index invalid input: '<' 0
    • clear Link icon

      public void clear()
      Clears the entire bitset
    • numBits Link icon

      public int numBits()
      Returns:
      the number of bits currently stored, not the highset set bit!
    • length Link icon

      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:
      the logical size of this bitset
    • notEmpty Link icon

      public boolean notEmpty()
      Returns:
      true if this bitset contains at least one bit set to true
    • isEmpty Link icon

      public boolean isEmpty()
      Returns:
      true if this bitset contains no bits that are set to true
    • nextSetBit Link icon

      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.
    • nextClearBit Link icon

      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.
    • and Link icon

      public Bits 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 - a bit set
    • andNot Link icon

      public Bits andNot(Bits other)
      Clears all of the bits in this bit set whose corresponding bit is set in the specified bit set.
      Parameters:
      other - a bit set
    • or Link icon

      public Bits 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 - a bit set
    • xor Link icon

      public Bits 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.
      Parameters:
      other - The other instance.
    • intersects Link icon

      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 - a bit set
      Returns:
      boolean indicating whether this bit set intersects the specified bit set
    • containsAll Link icon

      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 - a bit set
      Returns:
      boolean indicating whether this bit set is a super set of the specified set
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals Link icon

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • copy Link icon

      public Bits copy()
    • compareTo Link icon

      public int compareTo(Bits other)
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object