introduce bitloops

This commit is contained in:
mike
2026-01-17 16:03:16 +01:00
parent 9bd85c81a3
commit bfa19ec585
18 changed files with 40847 additions and 41296 deletions

View File

@@ -8,7 +8,7 @@ public final class HintScores {
public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/mike/dev/puzzle-generator/tools/hint/hint.sqlite")) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:tools/hint/hint.sqlite")) {
updateCrossScores(conn, HintScores::crossabilityScore, 1000);
}
}

View File

@@ -49,7 +49,7 @@ public class Meta {
return new ShardLem(Lemma.pack("XXX"), -1, new String[0]);
}
}
static final Path[] SHARDS = IntStream.range(0, 10).mapToObj(sId -> Path.of("/home/mike/dev/puzzle-generator/src/main/generated-sources/puzzle").resolve(sId + ".idx")).toArray(
static final Path[] SHARDS = IntStream.range(0, 10).mapToObj(sId -> Path.of("src/main/generated-sources/puzzle").resolve(sId + ".idx")).toArray(
Path[]::new);
static Path shardKey(long word) {
int L = Lemma.length(word);

View File

@@ -87,14 +87,12 @@ public class SwedishGenerator {
public static final Pick PICK_NOT_DONE = new Pick(null, null, 0);
@RequiredArgsConstructor
@Getter
@Accessors(fluent = true)
public static final class FillStats {
public double simplicity;
}
public static record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed, @Delegate FillStats stats) {
public static record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed, FillStats stats) {
}
@@ -144,16 +142,17 @@ public class SwedishGenerator {
static final long LETTER_MASK = (1L << 40) - 1; // low 40 bits
static final long INDEX_MASK = (1L << 24) - 1; // 24 bits
static long pack(String word) { return pack(word.getBytes(US_ASCII)); }
static long pack(int index, byte[] b) { return pack(b) | ((long) index << 40); }
static long pack(String word) { return pack(word.getBytes(US_ASCII)); }
static long packW(byte[] b) { return pack(b) /*| ((long) index << 40)*/; }
static long pack(byte[] b) {
long w = 0;
for (var i = 0; i < b.length; i++) w |= ((long) b[i] & 31) << (i * 5);
return w;
}
static public long from(int index, String word) { return pack(index, word.getBytes(US_ASCII)); }
static byte byteAt(long word, int idx) { return (byte) ((word >>> (idx * 5)) & 0b11111); }
static int length(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5) + 1; }
static public long from(String word) { return packW(word.getBytes(US_ASCII)); }
static byte byteAt(long word, int idx) { return (byte) ((word >>> (idx * 5)) & 0b11111); }
static int length(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5) + 1; }
static int length0(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5); }
static ThreadLocal<byte[]> BYTES = ThreadLocal.withInitial(() -> new byte[MAX_WORD_LENGTH]);
public static String asWord(long word) {
val len = Lemma.length(word);
@@ -413,10 +412,10 @@ public class SwedishGenerator {
var tries = Math.min(MAX_TRIES_PER_SLOT, N);
for (var t = 0; t < tries; t++) {
double r = rng.nextFloat();
var shardIndx = (int) (r * r * r * (N - 1));
var w = entry.words[shardIndx];
var lemIdx = Lemma.unpackIndex(w);
double r = rng.nextFloat();
var shardIdx = (int) (r * r * r * (N - 1));
var w = entry.words[shardIdx];
var lemIdx = Lemma.unpackIndex(w);
if (Bit1029.get(used, lemIdx)) continue;
low = glo;
top = ghi;
@@ -424,7 +423,7 @@ public class SwedishGenerator {
Bit1029.set(used, lemIdx);
s.assign.w = w;
s.assign.shardIdx = shardIndx;
s.assign.shardIdx = shardIdx;
if (backtrack(depth + 1)) return true;
s.assign.w = X;
Bit1029.clear(used, lemIdx);