introduce bitloops
This commit is contained in:
@@ -120,7 +120,6 @@ public record Export() {
|
|||||||
}
|
}
|
||||||
public String renderHuman() {
|
public String renderHuman() {
|
||||||
return String.join("\n", exportGrid(_ -> ' ', '#'));
|
return String.join("\n", exportGrid(_ -> ' ', '#'));
|
||||||
|
|
||||||
}
|
}
|
||||||
public boolean notClue(int c) { return grid.notClue(c); }
|
public boolean notClue(int c) { return grid.notClue(c); }
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
|||||||
@@ -263,11 +263,11 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
|||||||
var grid = new Grid(new byte[SIZE], lo, hi);
|
var grid = new Grid(new byte[SIZE], lo, hi);
|
||||||
for (var l = lo; l != X; l &= l - 1) {
|
for (var l = lo; l != X; l &= l - 1) {
|
||||||
int idx = Long.numberOfTrailingZeros(l);
|
int idx = Long.numberOfTrailingZeros(l);
|
||||||
grid.g[idx] = digitAt(idx);
|
grid.setLetter(idx, digitAt(idx));
|
||||||
}
|
}
|
||||||
for (var h = hi; h != X; h &= h - 1) {
|
for (var h = hi; h != X; h &= h - 1) {
|
||||||
int idx = 64 | Long.numberOfTrailingZeros(h);
|
int idx = 64 | Long.numberOfTrailingZeros(h);
|
||||||
grid.g[idx] = digitAt(idx);
|
grid.setLetter(idx, digitAt(idx));
|
||||||
}
|
}
|
||||||
return grid;
|
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 r(int offset) { return offset & 7; }
|
||||||
public static int c(int offset) { return offset >>> 3; }
|
public static int c(int offset) { return offset >>> 3; }
|
||||||
static int offset(int r, int c) { return r | (c << 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 setLetter(int idx, byte ch) { g[idx] = ch; }
|
||||||
void clearletter(int idx) { g[idx] = DASH; }
|
void clearletter(int idx) { g[idx] = DASH; }
|
||||||
@@ -877,8 +878,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
|||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int candidateCountForPattern(final long[] res, final long pattern, final DictEntry entry, final int numLongs) {
|
static int candidateCountForPattern(final long[] res, final long pattern, final long[][] posBitsets, final int numLongs) {
|
||||||
val posBitsets = entry.posBitsets;
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
|
|
||||||
for (long p = pattern; p != 0; ) {
|
for (long p = pattern; p != 0; ) {
|
||||||
@@ -963,7 +963,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
|||||||
if (assigned[s.key] != X) continue;
|
if (assigned[s.key] != X) continue;
|
||||||
var pattern = patternForSlot(grid, s);
|
var pattern = patternForSlot(grid, s);
|
||||||
var index = dictIndex[s.length()];
|
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) {
|
if (count == 0) {
|
||||||
current = PICK_NOT_DONE;
|
current = PICK_NOT_DONE;
|
||||||
|
|||||||
@@ -409,13 +409,13 @@ public class SwedishGeneratorTest {
|
|||||||
|
|
||||||
var ctx = Context.get();
|
var ctx = Context.get();
|
||||||
var pattern = packPattern("APP");
|
var pattern = packPattern("APP");
|
||||||
assertEquals(2, candidateCountForPattern(ctx.bitset(), pattern, entry5, entry5.numlong()));
|
assertEquals(2, candidateCountForPattern(ctx.bitset(), pattern, entry5.posBitsets(), entry5.numlong()));
|
||||||
|
|
||||||
pattern = packPattern("BAN");
|
pattern = packPattern("BAN");
|
||||||
assertEquals(1, candidateCountForPattern(ctx.bitset(), pattern, entry5, entry5.numlong()));
|
assertEquals(1, candidateCountForPattern(ctx.bitset(), pattern, entry5.posBitsets(), entry5.numlong()));
|
||||||
|
|
||||||
pattern = packPattern("CAT");
|
pattern = packPattern("CAT");
|
||||||
assertEquals(0, candidateCountForPattern(ctx.bitset(), pattern, entry5, entry5.numlong()));
|
assertEquals(0, candidateCountForPattern(ctx.bitset(), pattern, entry5.posBitsets(), entry5.numlong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user