introduce bitloops
This commit is contained in:
@@ -144,13 +144,11 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
public Grid(byte[] g) { this(g, new long[2]); }
|
||||
static Grid createEmpty() { return new Grid(new byte[SIZE], new long[2]); }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
|
||||
int digitAt(int index) { return g[index] - 48; }
|
||||
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); }
|
||||
Grid deepCopyGrid() { return new Grid(g.clone(), bo.clone()); }
|
||||
public byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
public byte byteAt(int pos) { return g[pos]; }
|
||||
void setByteAt(int idx, byte ch) { g[idx] = ch; }
|
||||
void setAt(int idx, byte ch) {
|
||||
@@ -168,9 +166,8 @@ public record SwedishGenerator(Rng rng) {
|
||||
if (idx < 64) bo[0] &= ~(1L << idx);
|
||||
else bo[1] &= ~(1L << (idx & 63));
|
||||
}
|
||||
static boolean isDigit(byte b) { return (b & 48) == 48; }
|
||||
boolean isDigitAt(int r, int c) { return isDigit(g[offset(r, c)]); }
|
||||
boolean isDigitAt(int index) { return isDigit(g[index]); }
|
||||
static boolean isDigit(byte b) { return (b & 48) == 48; }
|
||||
boolean isDigitAt(int index) { return isDigit(g[index]); }
|
||||
boolean isClue(int index) {
|
||||
if (index < 64) {
|
||||
return (bo[0] >> index & 1L) != 0;
|
||||
@@ -196,12 +193,10 @@ public record SwedishGenerator(Rng rng) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static boolean isLetter(byte b) { return (b & 64) != 0; }
|
||||
public boolean isLetterSet(int r, int c) { return isLetter(g[offset(r, c)]); }
|
||||
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||
static boolean notDigit(byte b) { return (b & 48) != 48; }
|
||||
public boolean isLetterAt(int r, int c) { return notDigit(g[offset(r, c)]); }
|
||||
public boolean isLetterAt(int index) { return notDigit(g[index]); }
|
||||
static boolean isLetter(byte b) { return (b & 64) != 0; }
|
||||
public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||
static boolean notDigit(byte b) { return (b & 48) != 48; }
|
||||
public boolean isLetterAt(int index) { return notDigit(g[index]); }
|
||||
|
||||
public double similarity(Grid b) {
|
||||
var same = 0;
|
||||
@@ -328,10 +323,10 @@ public record SwedishGenerator(Rng rng) {
|
||||
}
|
||||
|
||||
static int intersectSorted(int[] a, int aLen, int[] b, int bLen, int[] out) {
|
||||
int i = 0, j = 0, k = 0;
|
||||
int i = 0, j = 0, k = 0, x, y;
|
||||
while (i < aLen && j < bLen) {
|
||||
int x = a[i];
|
||||
int y = b[j];
|
||||
x = a[i];
|
||||
y = b[j];
|
||||
if (x == y) {
|
||||
out[k++] = x;
|
||||
i++;
|
||||
@@ -455,7 +450,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
long packed = Neighbors9x8.NBR8_PACKED[Grid.offset(rr, cc)];
|
||||
int n = (int) (packed >>> 56);
|
||||
for (int k = 0; k < n; k++) {
|
||||
int nidx = (int)((packed >>> (k * 7)) & 0x7F);
|
||||
int nidx = (int) ((packed >>> (k * 7)) & 0x7F);
|
||||
|
||||
if (seen.get(nidx) || grid.isLetterAt(nidx)) continue;
|
||||
seen.set(nidx);
|
||||
|
||||
Reference in New Issue
Block a user