(gamma) Fix readCount() behavior in EGC

This commit is contained in:
Viktor Lofgren 2024-06-25 22:17:54 +02:00
parent dae22ccbe0
commit b805f6daa8
2 changed files with 11 additions and 4 deletions

View File

@ -37,12 +37,12 @@ public class EliasGammaCodec implements IntIterator {
public static int readCount(ByteBuffer buffer) {
var reader = new BitReader(buffer);
if (reader.getCurrentValue() > 0) {
int bits = reader.takeWhileZero();
return reader.get(bits);
int bits = reader.takeWhileZero();
if (!reader.hasMore()) {
return 0;
}
else {
return 0;
return reader.get(bits);
}
}

View File

@ -30,6 +30,13 @@ class EliasGammaCodecTest {
assertEquals(expected, decoded);
}
@Test
public void valueCount() {
var ret = EliasGammaCodec.encode(work, new int[] { 1, 3, 5, 16, 32, 64 });
var count = EliasGammaCodec.readCount(ret);
assertEquals(6, count);
}
@Test
public void testCodec2() {
var ret = EliasGammaCodec.encode(work, new int[] { 1, 256 });