introduce bitloops

This commit is contained in:
mike
2026-01-12 10:38:24 +01:00
parent 67eedb773b
commit 6ef007522c
4 changed files with 14 additions and 27 deletions

View File

@@ -66,7 +66,6 @@ public record SwedishGenerator(Rng rng) {
static final byte B64 = (byte) 64;
static final byte B48 = (byte) 48;
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
static final nbrs_16[] OFFSETS_FOUR = Neighbors9x8.OFFSETS_FOUR;
static final rci[] IT = Neighbors9x8.IT;
static final int[][] MUTATE_RI = new int[SIZE][625];
static final long[] NBR8_PACKED_LO = Neighbors9x8.NBR8_PACKED_LO;
@@ -206,10 +205,8 @@ public record SwedishGenerator(Rng rng) {
return true;
}
static boolean isLetter(byte b) { return (b & B64) != B0; }
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
static boolean notDigit(byte b) { return (b & B48) != B48; }
public boolean isLetterAt(int index) { return notDigit(g[index]); }
static boolean isLetter(byte b) { return (b & B64) != B0; }
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
public double similarity(Grid b) {
var same = 0;
@@ -363,7 +360,6 @@ public record SwedishGenerator(Rng rng) {
int clueIdx = i | Long.numberOfTrailingZeros(bits);
var d = grid.digitAt(clueIdx);
long packed = OFFSETS_D_IDX[(d - 1) | (clueIdx << 2)];
//if (OFFSETS_D_IDX[(d-1) * SIZE + clueIdx] != packed) throw new IllegalStateException("Invalid path index for digit " + d + " at clue " + clueIdx);
int n = (int) (packed >>> 56) * 7, k, idx;
var horiz = Slot.horiz(d) ? covH : covV;
@@ -466,10 +462,10 @@ public record SwedishGenerator(Rng rng) {
for (int placed = 0, guard = 0, idx; placed < TARGET_CLUES && guard < 4000; guard++) {
idx = rng.randint(0, SIZE_MIN_1);
if (g.isClue(idx)) continue;
var d = OFFSETS_FOUR[rng.randint2bit()];
if (g.hasRoomForClue(d.path()[idx])) {
g.setClue(idx, d.dbyte());
int d_idx = rng.randint2bit();
val packed = OFFSETS_D_IDX[d_idx | idx << 2];
if (g.hasRoomForClue(packed)) {
g.setClue(idx, (byte) (1 + (d_idx | 48)));
placed++;
}
}
@@ -479,12 +475,12 @@ public record SwedishGenerator(Rng rng) {
var g = grid.deepCopyGrid();
int ri;
var bytes = MUTATE_RI[rng.randint(0, SIZE_MIN_1)];
nbrs_16 d;
for (var k = 0; k < 4; k++) {
ri = bytes[rng.randint(0, 624)];
if (!g.clueless(ri)) {
d = OFFSETS_FOUR[rng.randint2bit()];
if (g.hasRoomForClue(d.path()[ri])) g.setClue(ri, d.dbyte());
int d_idx = rng.randint2bit();
val packed = OFFSETS_D_IDX[d_idx | ri << 2];
if (g.hasRoomForClue(packed)) g.setClue(ri, (byte) (1 + (d_idx | 48)));
}
}
return g;