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  Bitfield.Factory
      Simple Bitfield factory for returning the efficient implementation.
      static class  Bitfield.Util
      Bit operation utilities (static).
    • Field Summary

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

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int bitCount()
      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 size()
      Returns the storage size in bit units, e.g.
    • Field Detail

      • UNSIGNED_INT_MAX_VALUE

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

      • 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(int, int, int)
      • 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:
        get32(int, int)
      • 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
      • 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