Class SSU2Bitfield

java.lang.Object
net.i2p.router.transport.udp.SSU2Bitfield

class SSU2Bitfield extends Object
Container of a long array representing set and unset bits. When a bit higher than the current size + offset is set, the offset shifts up and the lowest set bits are lost. Also contains methods to convert to/from an ACK block.
Since:
0.9.54
  • Constructor Details

    • SSU2Bitfield

      public SSU2Bitfield(int size, long offset)
      Creates a new SSU2Bitfield that represents size unset bits.
  • Method Details

    • size

      public int size()
    • getOffset

      public long getOffset()
    • set

      public boolean set(long bit) throws IndexOutOfBoundsException
      Sets the given bit to true. When a bit higher than the current size + offset is set, the offset shifts up and the lowest set bits are lost.
      Returns:
      previous value, true if previously set or unknown
      Throws:
      IndexOutOfBoundsException - if bit is smaller then zero OR if the shift is too big
    • get

      public boolean get(long bit)
      Return true if the bit is set or false if it is not.
      Throws:
      IndexOutOfBoundsException - if bit is smaller then zero
    • getHighestSet

      public long getHighestSet()
      Return the highest set bit, or -1 if none.
    • toAckBlock

      public SSU2Payload.AckBlock toAckBlock(int maxRanges)
      Parameters:
      maxRanges - may be 0
      Returns:
      null if nothing is set
    • fromACKBlock

      public static SSU2Bitfield fromACKBlock(long thru, int acnt, byte[] ranges, int rangeCount)
      Parameters:
      ranges - may be null
    • forEachAndNot

      public void forEachAndNot(SSU2Bitfield bf2, SSU2Bitfield.Callback cb)
      Callback for all bits set in this bitfield but not set in bf2. If this offset is greater than bf2's highest bit set, i.e. this bitfield is completely newer, calls back for all bits in this bitfield. If this highest bit set is less than than bf2's offset, i.e. this bitfield is completely older, the callback will not be called. Synchs on this and then on bf2. Usage: this is the received acks, bf2 is previously acked, callback for each newly acked.
    • toString

      public static String toString(long thru, int acnt, byte[] ranges, int rangeCount)
      Pretty print an ACK block
      Parameters:
      ranges - may be null
    • toString

      public String toString()
      Overrides:
      toString in class Object