introduce bitloops

This commit is contained in:
mike
2026-01-17 16:37:48 +01:00
parent c76d463c8c
commit 9367833407
38 changed files with 147 additions and 93 deletions

View File

@@ -153,7 +153,7 @@ public final class DictJavaGeneratorMulti {
writeLengthAssembler(outDir, pkg, base, L, rows, cols, words.length, flat.length, wChunks, pChunks);
}
/** Writes classes like Prefix0..PrefixN each with static final long[] DATA. Returns chunk count. */
/** Writes classes like Prefix0..PrefixN each with static long[] DATA. Returns chunk count. */
private static int writeChunkClasses(Path outDir, String pkg, String prefix, long[] data, int chunkSize) throws IOException {
int chunks = (data.length + chunkSize - 1) / chunkSize;
for (int ci = 0; ci < chunks; ci++) {
@@ -165,11 +165,14 @@ public final class DictJavaGeneratorMulti {
w.write("package " + pkg + ";\n\n");
w.write("public final class " + prefix + ci + " {\n");
w.write(" private " + prefix + ci + "() {}\n");
w.write(" public static final long[] DATA = new long[] {\n");
w.write(" public static long[] get() {\n");
w.write(" return new long[] { \n");
for (int i = from; i < to; i++) {
w.write(" " + toLongLiteral(data[i]) + (i + 1 < to ? "," : "") + "\n");
}
w.write(" };\n");
w.write(" }\n");
w.write("}\n");
}
}
@@ -194,22 +197,32 @@ public final class DictJavaGeneratorMulti {
// assemble words
w.write(" private static long[] words() {\n");
w.write(" long[] out = new long[WORDS_LEN];\n");
w.write(" int k = 0;\n");
for (int ci = 0; ci < wChunks; ci++) {
w.write(" k = copy(out, k, DictDataL" + L + "W" + ci + ".DATA);\n");
String wPrefix = "DictDataL" + L + "W";
if (wChunks == 1) {
w.write(" return " + wPrefix + "0.get();\n");
} else {
w.write(" long[] out = new long[WORDS_LEN];\n");
w.write(" int k = 0;\n");
for (int ci = 0; ci < wChunks; ci++) {
w.write(" k = copy(out, k, " + wPrefix + ci + ".get());\n");
}
w.write(" return out;\n");
}
w.write(" return out;\n");
w.write(" }\n\n");
// assemble pos
w.write(" private static long[] posFlat() {\n");
w.write(" long[] out = new long[POS_LEN];\n");
w.write(" int k = 0;\n");
for (int ci = 0; ci < pChunks; ci++) {
w.write(" k = copy(out, k, DictDataL" + L + "P" + ci + ".DATA);\n");
String pPrefix = "DictDataL" + L + "P";
if (pChunks == 1) {
w.write(" return " + pPrefix + "0.get();\n");
} else {
w.write(" long[] out = new long[POS_LEN];\n");
w.write(" int k = 0;\n");
for (int ci = 0; ci < pChunks; ci++) {
w.write(" k = copy(out, k, " + pPrefix + ci + ".get());\n");
}
w.write(" return out;\n");
}
w.write(" return out;\n");
w.write(" }\n\n");
// entry

View File

@@ -71,7 +71,7 @@ public class ExportFormatTest {
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
var puzzleResult = new PuzzleResult(new Clued(clues), grid, new Slotinfo[]{
new Slotinfo(key, lo, 0L, 0, new Assign(TEST, 0), null)
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null)
}, fillResult);
var rewards = new Rewards(10, 5, 1);
@@ -134,7 +134,7 @@ public class ExportFormatTest {
for (int i = 0; i < Math.min(words.length, 5); i++) {
val wordVal = words[i];
val word = Lemma.asWord(wordVal);
val assigned = new Assign(wordVal, i);
val assigned = new Assign(wordVal);
val shard = Meta.shardKey(assigned.w);
val clueRec = Meta.readRecord(shard, i);
@@ -149,15 +149,15 @@ public class ExportFormatTest {
@Test
void testSpecificWords() {
// These words are known to be in the CSV and likely in the dictionary
String[] testWords = {"EEN", "NAAR", "IEDEREEN"};
String[] testWords = { "EEN", "NAAR", "IEDEREEN" };
for (String wStr : testWords) {
long w = Lemma.pack(wStr);
int L = wStr.length();
var entry = DictData.DICT.index()[L];
long w = Lemma.pack(wStr);
int L = wStr.length();
var entry = DictData.DICT.index()[L];
if (entry == null) continue;
// Find index of word in entry
int idx = -1;
int idx = -1;
long[] words = entry.words();
for (int i = 0; i < words.length; i++) {
if (Lemma.asWord(words[i]).equals(wStr)) {
@@ -167,8 +167,8 @@ public class ExportFormatTest {
}
if (idx != -1) {
val shard = Meta.shardKey(w);
val clueRec = Meta.readRecord(shard, idx);
val shard = Meta.shardKey(w);
val clueRec = Meta.readRecord(shard, idx);
assertNotNull(clueRec);
assertEquals(wStr, Lemma.asWord(clueRec.w()));
// Check some expected complexity values (from CSV head output, column 3)