(slop) Add 32 bit read method for Varint along with the old 64 bit version

This commit is contained in:
Viktor Lofgren 2024-07-28 13:20:18 +02:00
parent 40f42bf654
commit e585116dab
3 changed files with 28 additions and 11 deletions

View File

@ -52,7 +52,7 @@ public record IndexJournalPage(Path baseDir, int page) {
return size.forPage(page).open(table, baseDir);
}
public LongColumnReader openTermCounts(SlopTable table) throws IOException {
public VarintColumnReader openTermCounts(SlopTable table) throws IOException {
return termCounts.forPage(page).open(table, baseDir);
}

View File

@ -75,18 +75,32 @@ public class VarintColumn {
return columnDesc;
}
public long get() throws IOException {
long value = 0;
public int get() throws IOException {
int value = 0;
int shift = 0;
byte b;
while (true) {
long b = reader.getByte();
do {
b = reader.getByte();
value |= (b & 0x7F) << shift;
shift += 7;
if ((b & 0x80) == 0) {
break;
}
}
} while ((b & 0x80) != 0);
position++;
return value;
}
public long getLong() throws IOException {
long value = 0;
int shift = 0;
byte b;
do {
b = reader.getByte();
value |= (long) (b & 0x7F) << shift;
shift += 7;
} while ((b & 0x80) != 0);
position++;

View File

@ -1,10 +1,13 @@
package nu.marginalia.slop.column.dynamic;
import nu.marginalia.slop.column.primitive.LongColumnReader;
import nu.marginalia.slop.column.primitive.IntColumnReader;
import java.io.IOException;
public interface VarintColumnReader extends LongColumnReader {
public interface VarintColumnReader extends IntColumnReader {
int get() throws IOException;
long getLong() throws IOException;
@Override
long position() throws IOException;