java.lang.Object
org.klomp.snark.BitField
org.klomp.snark.CompleteBitField

public class CompleteBitFieldextends BitField
A full bitfield, immutable, to save memory and time. Overrides all methods except size().
  • Field Summary

    Fields inherited from class BitField

    size
    Modifier and Type
    Field
    Description
    protected final int
    Number of bits this field spans, one per piece of the torrent.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CompleteBitField(int size)
    Creates a new CompleteBitField that represents size set bits.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    clear(int bit)
    Mark the given bit false.
    boolean
    Returns true if all bits are set.
    int
    Returns the number of set bits.
    boolean
    Compares this BitField to another object for equality.
    boolean
    get(int bit)
    Returns true if the bit is set or false if it is not.
    byte[]
    Returns the actual byte array used.
    int
    Returns a hash code value for this BitField.
    void
    set(int bit)
    Mark the given bit true.
    void
    Mark all bits true.
    Compact range representation - "BitField(128)[0-4 9 22-30]" instead of enumerating every set bit.

    Methods inherited from class BitField

    size
    Modifier and Type
    Method
    Description
    int
    Returns the size of the BitField.

    Methods inherited from class Object

    clone, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CompleteBitField

      public CompleteBitField(int size)
      Creates a new CompleteBitField that represents size set bits.
      Parameters:
      size - the number of bits in the bit field
  • Method Details

    • getFieldBytes

      public byte[] getFieldBytes()
      Description copied from class: BitField
      Returns the actual byte array used. Changes to this array affect this BitField. Note that some bits at the end of the byte array are supposed to be always unset if they represent bits bigger then the size of the bitfield.

      Caller should synchronize on this and copy!

      Overrides:
      getFieldBytes in class BitField
      Returns:
      the internal byte array representing the bit field
    • set

      public void set(int bit)
      Description copied from class: BitField
      Mark the given bit true.
      Overrides:
      set in class BitField
      Parameters:
      bit - the zero-based piece index to flip, in the range 0 to size-1
    • clear

      public void clear(int bit)
      Description copied from class: BitField
      Mark the given bit false.
      Overrides:
      clear in class BitField
      Parameters:
      bit - the zero-based piece index to flip, in the range 0 to size-1
    • setAll

      public void setAll()
      Description copied from class: BitField
      Mark all bits true.
      Overrides:
      setAll in class BitField
    • get

      public boolean get(int bit)
      Description copied from class: BitField
      Returns true if the bit is set or false if it is not.
      Overrides:
      get in class BitField
      Parameters:
      bit - the zero-based piece index to flip, in the range 0 to size-1
      Returns:
      true if the bit is set, false otherwise
    • count

      public int count()
      Description copied from class: BitField
      Returns the number of set bits.
      Overrides:
      count in class BitField
      Returns:
      the count of bits that are set to true
    • complete

      public boolean complete()
      Description copied from class: BitField
      Returns true if all bits are set.
      Overrides:
      complete in class BitField
      Returns:
      true if all bits are set (bit field is complete), false otherwise
    • hashCode

      public int hashCode()
      Description copied from class: BitField
      Returns a hash code value for this BitField.
      Overrides:
      hashCode in class BitField
      Returns:
      a hash code value for this BitField
    • equals

      public boolean equals(Object o)
      Description copied from class: BitField
      Compares this BitField to another object for equality.
      Overrides:
      equals in class BitField
      Parameters:
      o - the object to compare with
      Returns:
      true if the objects are equal, false otherwise
    • toString

      public String toString()
      Description copied from class: BitField
      Compact range representation - "BitField(128)[0-4 9 22-30]" instead of enumerating every set bit. Piece counts run into the thousands, and this is called from logging on hot paths.
      Overrides:
      toString in class BitField