Class BitVectorImpl

java.lang.Object
org.wikidata.wdtk.storage.datastructures.BitVectorImpl
All Implemented Interfaces:
Iterable<Boolean>, BitVector

public class BitVectorImpl extends Object implements BitVector, Iterable<Boolean>
Default implementation of BitVector. This implementation contains an array of long, and each long stores 64 bits. When more space is needed, the internal array grows exponentially. This bit vector is flexible, which means that:
  1. it is always possible to store a bit in any non-negative position without explicitly resizing the vector,
  2. any non-negative position outside the bit vector can be retrieved and contains a false.
Author:
Julian Mendez
  • Constructor Details

    • BitVectorImpl

      public BitVectorImpl()
      Constructor of a bit vector of size 0.
    • BitVectorImpl

      public BitVectorImpl(BitVector bitVector)
      Copy constructor of a bit vector.
      Parameters:
      bitVector - bit vector
    • BitVectorImpl

      public BitVectorImpl(long initialSize)
      Constructor of a bit vector of size initialSize. The bit vector contains false at all indexes.
      Parameters:
      initialSize - initial size of this bit vector
  • Method Details

    • addBit

      public boolean addBit(boolean bit)
      Description copied from interface: BitVector
      Appends a bit to this bit vector.
      Specified by:
      addBit in interface BitVector
      Returns:
      true if the element was successfully added
    • equals

      public boolean equals(Object obj)
      Description copied from interface: BitVector
      Returns true if and only if the specified object is also a BitVector and both contain the same bits in the same order.
      Specified by:
      equals in interface BitVector
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to be compared with this BitVector
      Returns:
      true if and only if the specified object is also a BitVector and both contain the same bits in the same order
    • getBit

      public boolean getBit(long position)
      Description copied from interface: BitVector
      This is the "access" method of bit vectors.
      Specified by:
      getBit in interface BitVector
      Returns:
      value of a bit at position
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • iterator

      public Iterator<Boolean> iterator()
      Specified by:
      iterator in interface BitVector
      Specified by:
      iterator in interface Iterable<Boolean>
      Returns:
      an iterator for this bit vector
    • setBit

      public void setBit(long position, boolean bit)
      Description copied from interface: BitVector
      Sets a bit at a particular position.
      Specified by:
      setBit in interface BitVector
      Parameters:
      position - position
      bit - bit
    • size

      public long size()
      Specified by:
      size in interface BitVector
      Returns:
      size of this bit vector
    • toString

      public String toString()
      Overrides:
      toString in class Object