mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
(gamma) Minor clean-up
This commit is contained in:
parent
b798f28443
commit
40bca93884
@ -17,8 +17,8 @@ import java.util.StringJoiner;
|
|||||||
public class GammaCodedSequence implements BinarySerializable, Iterable<Integer> {
|
public class GammaCodedSequence implements BinarySerializable, Iterable<Integer> {
|
||||||
private final ByteBuffer raw;
|
private final ByteBuffer raw;
|
||||||
|
|
||||||
int startPos = 0;
|
private final int startPos;
|
||||||
int startLimit = 0;
|
private final int startLimit;
|
||||||
|
|
||||||
/** Create a new GammaCodedSequence from a sequence of integers.
|
/** Create a new GammaCodedSequence from a sequence of integers.
|
||||||
*
|
*
|
||||||
@ -116,6 +116,9 @@ public class GammaCodedSequence implements BinarySerializable, Iterable<Integer>
|
|||||||
return sj.toString();
|
return sj.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the backing ByteBuffer of the sequence, configured with a position and limit
|
||||||
|
* that is equal to the relevant data range
|
||||||
|
*/
|
||||||
public ByteBuffer buffer() {
|
public ByteBuffer buffer() {
|
||||||
raw.position(startPos);
|
raw.position(startPos);
|
||||||
raw.limit(startLimit);
|
raw.limit(startLimit);
|
||||||
@ -123,11 +126,17 @@ public class GammaCodedSequence implements BinarySerializable, Iterable<Integer>
|
|||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the number of bytes used by the sequence in the buffer */
|
||||||
public int bufferSize() {
|
public int bufferSize() {
|
||||||
return raw.capacity();
|
return startLimit - startPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return the number of items in the sequence */
|
||||||
public int valueCount() {
|
public int valueCount() {
|
||||||
|
// if the first byte is zero, the sequence is empty and we can skip decoding
|
||||||
|
if (0 == raw.get(startPos))
|
||||||
|
return 0;
|
||||||
|
|
||||||
return EliasGammaCodec.readCount(buffer());
|
return EliasGammaCodec.readCount(buffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ public class BitWriter {
|
|||||||
|
|
||||||
var outBuffer = ByteBuffer.allocate(totalMeaningfulBytes);
|
var outBuffer = ByteBuffer.allocate(totalMeaningfulBytes);
|
||||||
|
|
||||||
outBuffer.put(underlying.array(), 0, totalMeaningfulBytes);
|
outBuffer.put(0, underlying, 0, totalMeaningfulBytes);
|
||||||
|
|
||||||
outBuffer.position(0);
|
outBuffer.position(0);
|
||||||
outBuffer.limit(totalMeaningfulBytes);
|
outBuffer.limit(totalMeaningfulBytes);
|
||||||
|
Loading…
Reference in New Issue
Block a user