introduce bitloops
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user