introduce bitloops
This commit is contained in:
@@ -10,7 +10,6 @@ import lombok.val;
|
||||
import precomp.Neighbors9x8;
|
||||
import precomp.Neighbors9x8.rci;
|
||||
import puzzle.Export.Bit1029;
|
||||
import puzzle.Export.ClueAt;
|
||||
import puzzle.Export.DictEntryDTO;
|
||||
import puzzle.Export.Gridded;
|
||||
import puzzle.Export.Strings;
|
||||
@@ -732,7 +731,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
}
|
||||
return best.grid;
|
||||
}
|
||||
static long patternForSlot2(final long glo, final long ghi, final byte[] g, final int key, final long lo, final long hi) {
|
||||
static long patternForSlot(final long glo, final long ghi, final byte[] g, final int key, final long lo, final long hi) {
|
||||
if (((lo & glo) | (hi & ghi)) == X) return 0;
|
||||
long p = 0;
|
||||
int n = 0;
|
||||
@@ -763,36 +762,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
}
|
||||
return p;
|
||||
}
|
||||
static long patternForSlot(final long glo, final long ghi, final byte[] g, final int key, final long lo, final long hi) {
|
||||
if (((lo & glo) | (hi & ghi)) == X) return 0;
|
||||
long p = 0;
|
||||
if (Slot.increasing(key)) {
|
||||
for (long b = lo & glo; b != X; b &= b - 1) {
|
||||
int idx = numberOfTrailingZeros(b);
|
||||
int i = bitCount(lo & ((1L << idx) - 1));
|
||||
p |= ((long) (i * 26 + g[idx])) << (i << 3);
|
||||
}
|
||||
int offset = bitCount(lo);
|
||||
for (long b = hi & ghi; b != X; b &= b - 1) {
|
||||
int idx = numberOfTrailingZeros(b);
|
||||
int i = offset + bitCount(hi & ((1L << idx) - 1));
|
||||
p |= ((long) (i * 26 + g[64 | idx])) << (i << 3);
|
||||
}
|
||||
} else {
|
||||
int offset = bitCount(hi);
|
||||
for (long b = hi & ghi; b != X; b &= b - 1) {
|
||||
int idx = numberOfTrailingZeros(b);
|
||||
int i = bitCount(hi & ~((1L << idx) | ((1L << idx) - 1)));
|
||||
p |= ((long) (i * 26 + g[64 | idx])) << (i << 3);
|
||||
}
|
||||
for (long b = lo & glo; b != X; b &= b - 1) {
|
||||
int idx = numberOfTrailingZeros(b);
|
||||
int i = offset + bitCount(lo & ~((1L << idx) | ((1L << idx) - 1)));
|
||||
p |= ((long) (i * 26 + g[idx])) << (i << 3);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
static int slotScore(byte[] count, long lo, long hi) {
|
||||
int cross = 0;
|
||||
for (long b = lo; b != X; b &= b - 1) cross += (count[numberOfTrailingZeros(b)] - 1);
|
||||
@@ -866,11 +835,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
|
||||
int[] indices = new int[count];
|
||||
for (int k = 0, ki = 0; k < numLongs; k++) {
|
||||
long w = res[k];
|
||||
while (w != X) {
|
||||
indices[ki++] = (k << 6) | numberOfTrailingZeros(w);
|
||||
w &= w - 1;
|
||||
}
|
||||
for (long w = res[k]; w != X; w &= w - 1) indices[ki++] = (k << 6) | numberOfTrailingZeros(w);
|
||||
}
|
||||
|
||||
return indices;
|
||||
@@ -977,7 +942,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
for (int i = 0, count, count2 = -1, bestScore = -1, n = TOTAL; i < n; i++) {
|
||||
var s = slots[i];
|
||||
if (s.assign.w != X) continue;
|
||||
var pattern = patternForSlot2(glo, ghi, g, s.key, s.lo, s.hi);
|
||||
var pattern = patternForSlot(glo, ghi, g, s.key, s.lo, s.hi);
|
||||
var index = s.entry;
|
||||
count = pattern == X ? index.length : candidateCountForPattern(bitset, pattern, index.posBitsets, index.numlong);
|
||||
|
||||
@@ -999,7 +964,7 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
|
||||
current = PICK_DONE;
|
||||
return;
|
||||
}
|
||||
var pattern = patternForSlot2(glo, ghi, g, best.key, best.lo, best.hi);
|
||||
var pattern = patternForSlot(glo, ghi, g, best.key, best.lo, best.hi);
|
||||
var index = best.entry;
|
||||
current = CARRIER;
|
||||
current.slot = best;
|
||||
|
||||
@@ -155,7 +155,7 @@ public class SwedishGeneratorTest {
|
||||
placeWord(grid, grid.g, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_2_0, 0, Lemma.from(0, "C"));
|
||||
var key = Slot.packSlotKey(OFF_1_0, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid.lo, grid.hi, grid.g, key, 7L, 0L);
|
||||
assertEquals(1L | (55L << 16), pattern);
|
||||
assertEquals(14081L, pattern);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user