Interface Bitfield


public interface Bitfield
Simple bitfield interface for efficient bit storage access in O(1).
Since:
2.3.2
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Simple Bitfield factory for returning the efficient implementation.
    static class 
    Bit operation utilities (static).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Maximum 32 bit Unsigned Integer Value: 0xffffffff == -1.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of one bits within this bitfield.
    void
    clear(int bitnum)
    Clear the bit at position bitnum according to bit.
    void
    clearField(boolean bit)
    Set all bits of this bitfield to the given value bit.
    boolean
    copy(int srcBitnum, int dstBitnum)
    Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set, otherwise false.
    int
    copy32(int srcLowBitnum, int dstLowBitnum, int length)
    Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.
    boolean
    get(int bitnum)
    Return true if the bit at position bitnum is set, otherwise false.
    int
    get32(int lowBitnum, int length)
    Returns length bits from this storage, starting with the lowest bit from the storage position lowBitnum.
    boolean
    put(int bitnum, boolean bit)
    Set or clear the bit at position bitnum according to bit and return the previous value.
    void
    put32(int lowBitnum, int length, int data)
    Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position lowBitnum.
    void
    set(int bitnum)
    Set the bit at position bitnum according to bit.
    int
    Returns the storage size in bit units, e.g.
  • Field Details

    • UNSIGNED_INT_MAX_VALUE

      static final int UNSIGNED_INT_MAX_VALUE
      Maximum 32 bit Unsigned Integer Value: 0xffffffff == -1.
      See Also:
  • Method Details

    • size

      int size()
      Returns the storage size in bit units, e.g. 32 bit for implementations using one int field.
    • clearField

      void clearField(boolean bit)
      Set all bits of this bitfield to the given value bit.
    • get32

      int get32(int lowBitnum, int length) throws IndexOutOfBoundsException
      Returns length bits from this storage, starting with the lowest bit from the storage position lowBitnum.
      Parameters:
      lowBitnum - storage bit position of the lowest bit, restricted to [0..size()-length].
      length - number of bits to read, constrained to [0..32].
      Throws:
      IndexOutOfBoundsException - if rightBitnum is out of bounds
      See Also:
    • put32

      void put32(int lowBitnum, int length, int data) throws IndexOutOfBoundsException
      Puts length bits of given data into this storage, starting w/ the lowest bit to the storage position lowBitnum.
      Parameters:
      lowBitnum - storage bit position of the lowest bit, restricted to [0..size()-length].
      length - number of bits to write, constrained to [0..32].
      data - the actual bits to be put into this storage
      Throws:
      IndexOutOfBoundsException - if rightBitnum is out of bounds
      See Also:
    • copy32

      int copy32(int srcLowBitnum, int dstLowBitnum, int length) throws IndexOutOfBoundsException
      Copies length bits at position srcLowBitnum to position dstLowBitnum and returning the bits.

      Implementation shall operate as if invoking get32(int, int) and then put32(int, int, int) sequentially.

      Parameters:
      srcLowBitnum - source bit number, restricted to [0..size()-1].
      dstLowBitnum - destination bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
      See Also:
    • get

      boolean get(int bitnum) throws IndexOutOfBoundsException
      Return true if the bit at position bitnum is set, otherwise false.
      Parameters:
      bitnum - bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
    • put

      boolean put(int bitnum, boolean bit) throws IndexOutOfBoundsException
      Set or clear the bit at position bitnum according to bit and return the previous value.
      Parameters:
      bitnum - bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
    • set

      void set(int bitnum) throws IndexOutOfBoundsException
      Set the bit at position bitnum according to bit.
      Parameters:
      bitnum - bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
    • clear

      void clear(int bitnum) throws IndexOutOfBoundsException
      Clear the bit at position bitnum according to bit.
      Parameters:
      bitnum - bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
    • copy

      boolean copy(int srcBitnum, int dstBitnum) throws IndexOutOfBoundsException
      Copies the bit at position srcBitnum to position dstBitnum and returning true if the bit is set, otherwise false.
      Parameters:
      srcBitnum - source bit number, restricted to [0..size()-1].
      dstBitnum - destination bit number, restricted to [0..size()-1].
      Throws:
      IndexOutOfBoundsException - if bitnum is out of bounds
    • bitCount

      int bitCount()
      Returns the number of one bits within this bitfield.

      Utilizes {#link Bitfield.Util.bitCount(int)}.