mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
(slop) Add signed 16 bit column type "short"
This commit is contained in:
parent
eaf7fbb9e9
commit
40f42bf654
@ -0,0 +1,89 @@
|
||||
package nu.marginalia.slop.column.primitive;
|
||||
|
||||
import nu.marginalia.slop.desc.ColumnDesc;
|
||||
import nu.marginalia.slop.storage.Storage;
|
||||
import nu.marginalia.slop.storage.StorageReader;
|
||||
import nu.marginalia.slop.storage.StorageWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ShortColumn {
|
||||
|
||||
public static ShortColumnReader open(Path path, ColumnDesc columnDesc) throws IOException {
|
||||
return new Reader(columnDesc, Storage.reader(path, columnDesc, true));
|
||||
}
|
||||
|
||||
public static ShortColumnWriter create(Path path, ColumnDesc columnDesc) throws IOException {
|
||||
return new Writer(columnDesc, Storage.writer(path, columnDesc));
|
||||
}
|
||||
|
||||
private static class Writer implements ShortColumnWriter {
|
||||
private final ColumnDesc<?, ?> columnDesc;
|
||||
private final StorageWriter storage;
|
||||
private long position = 0;
|
||||
|
||||
public Writer(ColumnDesc<?, ?> columnDesc, StorageWriter storageWriter) throws IOException {
|
||||
this.columnDesc = columnDesc;
|
||||
this.storage = storageWriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnDesc<?, ?> columnDesc() {
|
||||
return columnDesc;
|
||||
}
|
||||
|
||||
public void put(short value) throws IOException {
|
||||
storage.putShort(value);
|
||||
position++;
|
||||
}
|
||||
|
||||
public long position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
storage.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Reader implements ShortColumnReader {
|
||||
private final ColumnDesc<?, ?> columnDesc;
|
||||
private final StorageReader storage;
|
||||
|
||||
public Reader(ColumnDesc<?, ?> columnDesc, StorageReader storage) throws IOException {
|
||||
this.columnDesc = columnDesc;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public short get() throws IOException {
|
||||
return storage.getShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColumnDesc<?, ?> columnDesc() {
|
||||
return columnDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long position() throws IOException {
|
||||
return storage.position() / Short.BYTES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skip(long positions) throws IOException {
|
||||
storage.skip(positions, Short.BYTES);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasRemaining() throws IOException {
|
||||
return storage.hasRemaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
storage.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package nu.marginalia.slop.column.primitive;
|
||||
|
||||
import nu.marginalia.slop.column.ColumnReader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ShortColumnReader extends ColumnReader, AutoCloseable {
|
||||
short get() throws IOException;
|
||||
void close() throws IOException;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package nu.marginalia.slop.column.primitive;
|
||||
|
||||
import nu.marginalia.slop.column.ColumnWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface ShortColumnWriter extends ColumnWriter, AutoCloseable {
|
||||
void put(short value) throws IOException;
|
||||
|
||||
void close() throws IOException;
|
||||
}
|
@ -33,6 +33,8 @@ public abstract class ColumnType<
|
||||
public static ColumnType<ByteColumnReader, ByteColumnWriter> BYTE = register("s8", ByteOrder.nativeOrder(), ByteColumn::open, ByteColumn::create);
|
||||
public static ColumnType<CharColumnReader, CharColumnWriter> CHAR_LE = register("u16le", ByteOrder.LITTLE_ENDIAN, CharColumn::open, CharColumn::create);
|
||||
public static ColumnType<CharColumnReader, CharColumnWriter> CHAR_BE = register("u16be", ByteOrder.BIG_ENDIAN, CharColumn::open, CharColumn::create);
|
||||
public static ColumnType<ShortColumnReader, ShortColumnWriter> SHORT_LE = register("s16le", ByteOrder.LITTLE_ENDIAN, ShortColumn::open, ShortColumn::create);
|
||||
public static ColumnType<ShortColumnReader, ShortColumnWriter> SHORT_BE = register("s16be", ByteOrder.BIG_ENDIAN, ShortColumn::open, ShortColumn::create);
|
||||
public static ColumnType<IntColumnReader, IntColumnWriter> INT_LE = register("s32le", ByteOrder.LITTLE_ENDIAN, IntColumn::open, IntColumn::create);
|
||||
public static ColumnType<IntColumnReader, IntColumnWriter> INT_BE = register("s32be", ByteOrder.BIG_ENDIAN, IntColumn::open, IntColumn::create);
|
||||
public static ColumnType<LongColumnReader, LongColumnWriter> LONG_LE = register("s64le", ByteOrder.LITTLE_ENDIAN, LongColumn::open, LongColumn::create);
|
||||
|
Loading…
Reference in New Issue
Block a user