(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); 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); return termCounts.forPage(page).open(table, baseDir);
} }

View File

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

View File

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