introduce bitloops
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package puzzle;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.val;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -30,14 +29,10 @@ public class Meta {
|
||||
static final Path dir = projectRoot.resolve("src/main/resources/shards");
|
||||
static final Path shardData = dir.resolve("shard0.data");
|
||||
static final Path shardMap = dir.resolve("shard0.map");
|
||||
static String normWord(String s) {
|
||||
// belangrijk: zelfde normalisatie bij build en query
|
||||
return s.toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
// --- Lookup: w -> i using mmap ---
|
||||
static int findIndexInMapMmap(Path mapFile, long target) throws IOException {
|
||||
try (var ch = FileChannel.open(mapFile, StandardOpenOption.READ)) {
|
||||
static int findIndexInMapMmap(long target) throws IOException {
|
||||
try (var ch = FileChannel.open(Meta.shardMap, StandardOpenOption.READ)) {
|
||||
var mbb = (MappedByteBuffer) ch.map(FileChannel.MapMode.READ_ONLY, 0, ch.size()).order(ORDER);
|
||||
|
||||
var magic = mbb.getInt(0);
|
||||
@@ -60,8 +55,8 @@ public class Meta {
|
||||
}
|
||||
|
||||
// --- Read record i from shard.data (your format) ---
|
||||
static ShardLem readRecord(Path shardFile, long w, int i) throws IOException {
|
||||
try (var ch = FileChannel.open(shardFile, StandardOpenOption.READ)) {
|
||||
static ShardLem readRecord(long w, int i) throws IOException {
|
||||
try (var ch = FileChannel.open(Meta.shardData, StandardOpenOption.READ)) {
|
||||
var hdr = ByteBuffer.allocate(12).order(ORDER);
|
||||
ch.read(hdr);
|
||||
hdr.flip();
|
||||
@@ -105,10 +100,10 @@ public class Meta {
|
||||
// --- Demo main ---
|
||||
public static ShardLem lookup(long w) {
|
||||
try {
|
||||
var i = findIndexInMapMmap(shardMap, Lemma.pack43(w));
|
||||
var i = findIndexInMapMmap(Lemma.pack43(w));
|
||||
System.out.println("\nQuery: w=" + w + " -> i=" + i);
|
||||
if (i >= 0) {
|
||||
var rec = readRecord(shardData, w, i);
|
||||
var rec = readRecord(w, i);
|
||||
System.out.println(" simpel=" + rec.simpel());
|
||||
System.out.println(" clues=" + Arrays.toString(rec.clues()));
|
||||
return rec;
|
||||
@@ -117,7 +112,6 @@ public class Meta {
|
||||
throw new RuntimeException("NOT FOUND");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user