introduce bitloops

This commit is contained in:
mike
2026-01-12 19:32:05 +01:00
parent c7d67bf778
commit 368473c80f
3 changed files with 27 additions and 22 deletions

View File

@@ -58,7 +58,7 @@ public record SwedishGenerator(Rng rng) {
static final char C_DASH = '\0';
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
static final ThreadLocal<Context> CTX = ThreadLocal.withInitial(Context::new);
static boolean isLetter(byte b) { return (b & 64) != 0; }
static int clamp(int x, int a, int b) { return Math.max(a, Math.min(b, x)); }
record Pick(Slot slot, CandidateInfo info, boolean done) { }
@@ -108,6 +108,7 @@ public record SwedishGenerator(Rng rng) {
stats.simplicity = clueMap.isEmpty() ? 0 : stats.simplicity / clueMap.size();
}
}
}
static final class Context {
@@ -185,7 +186,6 @@ public record SwedishGenerator(Rng rng) {
if ((idx & 64) == 0) lo &= ~(1L << idx);
else hi &= ~(1L << (idx & 63));
}
static boolean isDigit(byte b) { return (b & B48) == B48; }
boolean isClue(long index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) != X : ((hi >>> (index & 63)) & 1L) != X; }
boolean isClue(int index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) != X : ((hi >>> (index & 63)) & 1L) != X; }
boolean notClue(long index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) == X : ((hi >>> (index & 63)) & 1L) == X; }
@@ -537,7 +537,7 @@ 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;
int d_idx = rng.randint2bit();
int d_idx = rng.randint2bit();
if (g.hasRoomForClue(OFFSETS_D_IDX[d_idx | idx << 2])) {
g.setClue(idx, (byte) (1 + (d_idx | 48)));
placed++;
@@ -572,7 +572,7 @@ public record SwedishGenerator(Rng rng) {
byte ch = b.g[i];
if (out.g[i] != ch) {
out.g[i] = ch;
if (Grid.isDigit(ch)) {
if (b.isClue(i)) {
if ((i & 64) == 0) bo0 |= (1L << i);
else bo1 |= (1L << (i & 63));
} else {