introduce bitloops
This commit is contained in:
@@ -303,30 +303,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
g[idx] = ch;
|
||||
}
|
||||
void setLetter(int idx, byte ch) {
|
||||
if ((idx & 64) == 0)
|
||||
setLetterLo(idx, ch);
|
||||
else
|
||||
setLetterHi(idx, ch);
|
||||
}
|
||||
|
||||
private void clearletterLo(int idx) {
|
||||
g[idx] = DASH;
|
||||
|
||||
lo &= ~(1L << idx);
|
||||
}
|
||||
private void clearletterHi(int idx) {
|
||||
g[idx] = DASH;
|
||||
|
||||
hi &= ~(1L << (idx & 63));
|
||||
}
|
||||
void undoPlace(long maskLo, long maskHi) {
|
||||
lo &= ~maskLo;
|
||||
hi &= ~maskHi;
|
||||
|
||||
/*for (long b = maskLo; b != 0; b &= b - 1) clearletterLo(Long.numberOfTrailingZeros(b));
|
||||
for (long b = maskHi; b != 0; b &= b - 1) clearletterHi(64 | Long.numberOfTrailingZeros(b));*/
|
||||
}
|
||||
}
|
||||
|
||||
static record DictEntry(long[] words, long[][] posBitsets, int length, int numlong) { }
|
||||
@@ -799,7 +775,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
for (long b = s.hi; b != 0; b &= b - 1) cross += (count[64 | Long.numberOfTrailingZeros(b)] - 1);
|
||||
return cross * 10 + s.length();
|
||||
}
|
||||
static boolean placeWord(Grid grid, Slot s, long w, long[] undoBuffer, int offset) {
|
||||
static boolean placeWord(Grid grid, Slot s, long w) {
|
||||
if (s.increasing()) {
|
||||
for (long b = s.lo & grid.lo; b != 0; b &= b - 1) {
|
||||
int idx = Long.numberOfTrailingZeros(b);
|
||||
@@ -824,8 +800,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
grid.lo |= maskLo;
|
||||
grid.hi |= maskHi;
|
||||
}
|
||||
undoBuffer[offset << 1] = maskLo;
|
||||
undoBuffer[(offset << 1) | 1] = maskHi;
|
||||
} else {
|
||||
int bcHi = Long.bitCount(s.hi);
|
||||
for (long b = s.hi & grid.hi; b != 0; b &= b - 1) {
|
||||
@@ -850,8 +824,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
grid.lo |= maskLo;
|
||||
grid.hi |= maskHi;
|
||||
}
|
||||
undoBuffer[offset << 1] = maskLo;
|
||||
undoBuffer[(offset << 1) | 1] = maskHi;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -932,7 +904,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
val used = new Bit1029();
|
||||
val assigned = new long[CLUE_INDEX_MAX_SIZE];
|
||||
val bitset = new long[2500];
|
||||
val undo = new long[64];
|
||||
|
||||
val TOTAL = slots.length;
|
||||
val slotScores = new int[TOTAL];
|
||||
@@ -1042,8 +1013,9 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
var w = entry.words[idx];
|
||||
var lemIdx = Lemma.unpackIndex(w);
|
||||
if (used.get(lemIdx)) continue;
|
||||
|
||||
if (!placeWord(grid, s, w, undo, depth)) continue;
|
||||
val low = grid.lo;
|
||||
val top = grid.hi;
|
||||
if (!placeWord(grid, s, w)) continue;
|
||||
|
||||
used.set(lemIdx);
|
||||
assigned[k] = w;
|
||||
@@ -1052,7 +1024,9 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
assigned[k] = X;
|
||||
used.clear(lemIdx);
|
||||
grid.undoPlace(undo[depth << 1], undo[(depth << 1) | 1]);
|
||||
//grid.undoPlace(undo[depth << 1], undo[(depth << 1) | 1]);
|
||||
grid.lo = low;
|
||||
grid.hi = top;
|
||||
}
|
||||
backtracks++;
|
||||
return false;
|
||||
@@ -1067,8 +1041,9 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
var w = entry.words[idxInArray];
|
||||
var lemIdx = Lemma.unpackIndex(w);
|
||||
if (used.get(lemIdx)) continue;
|
||||
|
||||
if (!placeWord(grid, s, w, undo, depth)) continue;
|
||||
val low = grid.lo;
|
||||
val top = grid.hi;
|
||||
if (!placeWord(grid, s, w)) continue;
|
||||
|
||||
used.set(lemIdx);
|
||||
assigned[k] = w;
|
||||
@@ -1077,7 +1052,9 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
assigned[k] = X;
|
||||
used.clear(lemIdx);
|
||||
grid.undoPlace(undo[depth << 1], undo[(depth << 1) | 1]);
|
||||
grid.lo = low;
|
||||
grid.hi = top;
|
||||
//grid.undoPlace(undo[depth << 1], undo[(depth << 1) | 1]);
|
||||
}
|
||||
|
||||
backtracks++;
|
||||
|
||||
Reference in New Issue
Block a user