Package net.i2p.router.transport.udp
Class SSU2Bitfield
java.lang.Object
net.i2p.router.transport.udp.SSU2Bitfield
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
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionSSU2Bitfield
(int size, long offset) Creates a new SSU2Bitfield that representssize
unset bits. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Callback for all bits set in this bitfield but not set in bf2.static SSU2Bitfield
fromACKBlock
(long thru, int acnt, byte[] ranges, int rangeCount) boolean
get
(long bit) Return true if the bit is set or false if it is not.long
Return the highest set bit, or -1 if none.long
boolean
set
(long bit) Sets the given bit to true.int
size()
toAckBlock
(int maxRanges) toString()
static String
toString
(long thru, int acnt, byte[] ranges, int rangeCount) Pretty print an ACK block
-
Constructor Details
-
SSU2Bitfield
public SSU2Bitfield(int size, long offset) Creates a new SSU2Bitfield that representssize
unset bits.
-
-
Method Details
-
size
public int size() -
getOffset
public long getOffset() -
set
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
- Parameters:
maxRanges
- may be 0- Returns:
- null if nothing is set
-
fromACKBlock
- Parameters:
ranges
- may be null
-
forEachAndNot
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
Pretty print an ACK block- Parameters:
ranges
- may be null
-
toString
-