Class BitSet32

java.lang.Object
Jcg.util.BitSet32
All Implemented Interfaces:
BitSetInterface

public class BitSet32 extends Object implements BitSetInterface
An implementation of a bit-vector (using memory words on 32 bits)
Author:
Luca Castelli Aleardi (older version by Yonik)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int[]
     
    int
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    BitSet32(int bitsSize)
    Constructs a BitSet large enough to hold numBits.
    BitSet32(int[] bits, int bitsSize)
    Constructs a BitSet, from an array already initialized
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the size in term of bits
    void
    clear(int index)
    Clears a bit.
    boolean
    get(int index)
     
    int
    getBit(int index)
    Returns 1 if the bit is set, 0 if not.
    void
    set(int index)
     
    int
    Returns the size of the bitset (number of words)
    byte[]
    Return an array of bytes storing the whole bit set
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • bits

      public int[] bits
    • numBits

      public int numBits
    • wordsLength

      private int wordsLength
    • wordSize

      private int wordSize
  • Constructor Details

    • BitSet32

      public BitSet32(int bitsSize)
      Constructs a BitSet large enough to hold numBits.
      Parameters:
      numBits - number of bits
    • BitSet32

      public BitSet32(int[] bits, int bitsSize)
      Constructs a BitSet, from an array already initialized
      Parameters:
      bits - an array of integers storing the BitSet
      numBits - number of bits
  • Method Details

    • size

      public int size()
      Returns the size of the bitset (number of words)
      Specified by:
      size in interface BitSetInterface
    • bitSize

      public int bitSize()
      Returns the size in term of bits
      Specified by:
      bitSize in interface BitSetInterface
    • get

      public boolean get(int index)
      Specified by:
      get in interface BitSetInterface
    • getBit

      public int getBit(int index)
      Returns 1 if the bit is set, 0 if not. The index should be less than the OpenBitSet size LCA: a' controler
      Specified by:
      getBit in interface BitSetInterface
    • set

      public void set(int index)
      Specified by:
      set in interface BitSetInterface
    • clear

      public void clear(int index)
      Clears a bit. The index should be less than the OpenBitSet size.
      Specified by:
      clear in interface BitSetInterface
    • toByteArray

      public byte[] toByteArray()
      Return an array of bytes storing the whole bit set

      Remark: the array of bytes is of size 4*W, where W is the number of words storing the bit set which is: size(bit set)/32

      Returns:
      an array of bytes, storing the values in the bit set
    • toString

      public String toString()
      Overrides:
      toString in class Object