introduce bitloops
This commit is contained in:
@@ -289,8 +289,8 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
return lisLetterAtHi(pos);
|
||||
}
|
||||
|
||||
public boolean lisLetterAtLo(int pos) { return (lo & (1L << pos)) != 0; }
|
||||
public boolean lisLetterAtHi(int pos) { return (hi & (1L << (pos & 63))) != 0; }
|
||||
public boolean lisLetterAtLo(int pos) { return (lo & (1L << pos)) != X; }
|
||||
public boolean lisLetterAtHi(int pos) { return (hi & (1L << (pos & 63))) != X; }
|
||||
void setLetterLo(int idx, byte ch) {
|
||||
lo |= (1L << idx);
|
||||
|
||||
@@ -411,11 +411,11 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
if (Slot.increasing(key)) {
|
||||
// first clue is lowest index among hits (lo first, then hi)
|
||||
if (hitsLo != 0) {
|
||||
if (hitsLo != X) {
|
||||
long stop = 1L << Long.numberOfTrailingZeros(hitsLo);
|
||||
rayLo &= (stop - 1);
|
||||
rayHi = 0; // any hi is beyond the stop
|
||||
} else if (hitsHi != 0) {
|
||||
} else if (hitsHi != X) {
|
||||
long stop = 1L << Long.numberOfTrailingZeros(hitsHi);
|
||||
// keep all lo (lo indices are < any hi index), but cut hi below stop
|
||||
rayHi &= (stop - 1);
|
||||
@@ -471,7 +471,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
if (hLo != X) {
|
||||
rLo &= ((1L << Long.numberOfTrailingZeros(hLo)) - 1);
|
||||
rHi = 0;
|
||||
} else if (hHi != 0) { rHi &= ((1L << Long.numberOfTrailingZeros(hHi)) - 1); }
|
||||
} else if (hHi != X) { rHi &= ((1L << Long.numberOfTrailingZeros(hHi)) - 1); }
|
||||
} else {
|
||||
if (hHi != X) {
|
||||
int msb = 63 - Long.numberOfLeadingZeros(hHi);
|
||||
@@ -563,8 +563,8 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
int clueIdx = Long.numberOfTrailingZeros(bits);
|
||||
var rci = IT[clueIdx];
|
||||
if ((4 - rci.nbrCount()) + Long.bitCount(rci.n1() & lo_cl) + Long.bitCount(rci.n2() & hi_cl) >= 3) penalty += 400;
|
||||
boolean h = (cHLo & (1L << clueIdx)) != 0;
|
||||
boolean v = (cVLo & (1L << clueIdx)) != 0;
|
||||
boolean h = (cHLo & (1L << clueIdx)) != X;
|
||||
boolean v = (cVLo & (1L << clueIdx)) != X;
|
||||
if (!h && !v) penalty += 1500;
|
||||
else if (h && v) { /* ok */ } else if (h | v) penalty += 200;
|
||||
else penalty += 600;
|
||||
@@ -573,8 +573,8 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
int clueIdx = Long.numberOfTrailingZeros(bits);
|
||||
var rci = IT[64 | clueIdx];
|
||||
if ((4 - rci.nbrCount()) + Long.bitCount(rci.n1() & lo_cl) + Long.bitCount(rci.n2() & hi_cl) >= 3) penalty += 400;
|
||||
boolean h = (cHHi & (1L << clueIdx)) != 0;
|
||||
boolean v = (cVHi & (1L << clueIdx)) != 0;
|
||||
boolean h = (cHHi & (1L << clueIdx)) != X;
|
||||
boolean v = (cVHi & (1L << clueIdx)) != X;
|
||||
if (!h && !v) penalty += 1500;
|
||||
else if (h && v) { /* ok */ } else if (h | v) penalty += 200;
|
||||
else penalty += 600;
|
||||
@@ -772,7 +772,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
static boolean placeWord(Grid grid, final int key, final long lo, final long hi, final long w) {
|
||||
final long glo = grid.lo, ghi = grid.hi;
|
||||
if (Slot.increasing(key)) {
|
||||
for (long b = lo & glo; b != 0; b &= b - 1) {
|
||||
for (long b = lo & glo; b != X; b &= b - 1) {
|
||||
int idx = Long.numberOfTrailingZeros(b);
|
||||
if (grid.g[idx] != Lemma.byteAt(w, Long.bitCount(lo & ((1L << idx) - 1)))) return false;
|
||||
}
|
||||
@@ -808,7 +808,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
long maskLo = lo & ~glo, maskHi = hi & ~ghi;
|
||||
if ((maskLo | maskHi) != X) {
|
||||
for (long b = maskHi; b != 0; b &= b - 1) {
|
||||
for (long b = maskHi; b != X; b &= b - 1) {
|
||||
int idx = Long.numberOfTrailingZeros(b);
|
||||
grid.g[64 | idx] = Lemma.byteAt(w, Long.bitCount(hi & ~((1L << idx) | ((1L << idx) - 1))));
|
||||
}
|
||||
@@ -828,7 +828,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
for (long p = pattern; p != X; ) {
|
||||
int combined = (int) (p & 0xFF);
|
||||
if (combined != 0) {
|
||||
if (combined != X) {
|
||||
long[] bs = posBitsets[combined - 1];
|
||||
if (first) {
|
||||
System.arraycopy(bs, 0, res, 0, numLongs);
|
||||
@@ -864,7 +864,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
for (long p = pattern; p != X; ) {
|
||||
int combined = (int) (p & 0xFF);
|
||||
if (combined != 0) {
|
||||
if (combined != X) {
|
||||
long[] bs = posBitsets[combined - 1];
|
||||
if (first) {
|
||||
System.arraycopy(bs, 0, res, 0, numLongs);
|
||||
|
||||
Reference in New Issue
Block a user