introduce bitloops

This commit is contained in:
mike
2026-01-14 08:24:53 +01:00
parent 352e8c79ca
commit aafa5d4d43
2 changed files with 23 additions and 25 deletions

View File

@@ -286,19 +286,18 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
}
}
static record Grid(byte[] g, long lo, long hi) {
@AllArgsConstructor
static class Grid {
public Grid(byte[] g) { this(g, 0, 0); }
static Grid createEmpty() { return new Grid(new byte[SIZE], X, X); }
public static int r(int offset) { return offset & 7; }
public static int c(int offset) { return offset >>> 3; }
static int offset(int r, int c) { return r | (c << 3); }
final byte[] g;
public long lo, hi;
public static int r(int offset) { return offset & 7; }
public static int c(int offset) { return offset >>> 3; }
static int offset(int r, int c) { return r | (c << 3); }
/// the pos will never target a clue
public byte letter32At(int pos) { return g[pos]; }
public byte letter32At(int pos) { return g[pos]; }
void setLetter(int idx, byte ch) { g[idx] = ch; }
void clearletter(int idx) { g[idx] = DASH; }
boolean isClue(int index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) != X : ((hi >>> (index & 63)) & 1L) != X; }
boolean notClue(int index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) == X : ((hi >>> (index & 63)) & 1L) == X; }
void undoPlace(long maskLo, long maskHi) {
for (long b = maskLo; b != 0; b &= b - 1) clearletter(Long.numberOfTrailingZeros(b));