introduce bitloops
This commit is contained in:
@@ -263,11 +263,11 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
var grid = new Grid(new byte[SIZE], lo, hi);
|
||||
for (var l = lo; l != X; l &= l - 1) {
|
||||
int idx = Long.numberOfTrailingZeros(l);
|
||||
grid.g[idx] = digitAt(idx);
|
||||
grid.setLetter(idx, digitAt(idx));
|
||||
}
|
||||
for (var h = hi; h != X; h &= h - 1) {
|
||||
int idx = 64 | Long.numberOfTrailingZeros(h);
|
||||
grid.g[idx] = digitAt(idx);
|
||||
grid.setLetter(idx, digitAt(idx));
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
@@ -293,6 +293,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
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]; }
|
||||
void setLetter(int idx, byte ch) { g[idx] = ch; }
|
||||
void clearletter(int idx) { g[idx] = DASH; }
|
||||
@@ -842,7 +843,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
}
|
||||
|
||||
static int[] candidateInfoForPattern(long[] res, long pattern, long[][] posBitsets, int numLongs) {
|
||||
boolean first = true;
|
||||
boolean first = true;
|
||||
|
||||
for (long p = pattern; p != 0; ) {
|
||||
int combined = (int) (p & 0xFF);
|
||||
@@ -877,9 +878,8 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
return indices;
|
||||
}
|
||||
|
||||
static int candidateCountForPattern(final long[] res, final long pattern, final DictEntry entry, final int numLongs) {
|
||||
val posBitsets = entry.posBitsets;
|
||||
boolean first = true;
|
||||
static int candidateCountForPattern(final long[] res, final long pattern, final long[][] posBitsets, final int numLongs) {
|
||||
boolean first = true;
|
||||
|
||||
for (long p = pattern; p != 0; ) {
|
||||
int combined = (int) (p & 0xFF);
|
||||
@@ -963,7 +963,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
if (assigned[s.key] != X) continue;
|
||||
var pattern = patternForSlot(grid, s);
|
||||
var index = dictIndex[s.length()];
|
||||
count = pattern == X ? index.length : candidateCountForPattern(bitset, pattern, index, index.numlong);
|
||||
count = pattern == X ? index.length : candidateCountForPattern(bitset, pattern, index.posBitsets, index.numlong);
|
||||
|
||||
if (count == 0) {
|
||||
current = PICK_NOT_DONE;
|
||||
|
||||
Reference in New Issue
Block a user