introduce bitloops
This commit is contained in:
@@ -272,6 +272,10 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
}
|
||||
return grid;
|
||||
}
|
||||
public void forEachSlot(SlotVisitor visitor) {
|
||||
for (var l = lo; l != X; l &= l - 1) processSlot(this, visitor, Long.numberOfTrailingZeros(l));
|
||||
for (var h = hi; h != X; h &= h - 1) processSlot(this, visitor, 64 | Long.numberOfTrailingZeros(h));
|
||||
}
|
||||
}
|
||||
|
||||
static record Grid(byte[] g, long lo, long hi) {
|
||||
@@ -291,10 +295,6 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
boolean notClue(int index) { return ((index & 64) == 0) ? ((lo >>> index) & 1L) == X : ((hi >>> (index & 63)) & 1L) == X; }
|
||||
int clueCount() { return Long.bitCount(lo) + Long.bitCount(hi); }
|
||||
|
||||
void forEachSlot(SlotVisitor visitor) {
|
||||
for (var l = lo; l != X; l &= l - 1) processSlot(this, visitor, Long.numberOfTrailingZeros(l));
|
||||
for (var h = hi; h != X; h &= h - 1) processSlot(this, visitor, 64 | Long.numberOfTrailingZeros(h));
|
||||
}
|
||||
void undoPlace(long maskLo, long maskHi) {
|
||||
for (long b = maskLo; b != 0; b &= b - 1) clearletter(Long.numberOfTrailingZeros(b));
|
||||
for (long b = maskHi; b != 0; b &= b - 1) clearletter(64 | Long.numberOfTrailingZeros(b));
|
||||
@@ -401,7 +401,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
public static int packSlotDir(int idx, int d) { return (idx << BIT_FOR_DIR) | d; }
|
||||
}
|
||||
|
||||
private static void processSlot(Grid grid, SlotVisitor visitor, int idx) {
|
||||
private static void processSlot(Clues grid, SlotVisitor visitor, int idx) {
|
||||
int key = Slot.packSlotDir(idx, grid.digitAt(idx)); // 0..3
|
||||
|
||||
long rayLo = PATH_LO[key];
|
||||
@@ -443,7 +443,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
//if ((rayLo | rayHi) == 0L) throw new RuntimeException()
|
||||
}
|
||||
|
||||
static Slot[] extractSlots(Grid grid) {
|
||||
static Slot[] extractSlots(Clues grid) {
|
||||
var slots = new Slot[grid.clueCount()];
|
||||
int[] N = new int[]{ 0 };
|
||||
grid.forEachSlot((key, lo, hi) -> slots[N[0]++] = Slot.from(key, lo, hi));
|
||||
@@ -910,7 +910,7 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
for (int i = 0; i < slots.length; i++) slotScores[i] = slotScore(count, slots[i]);
|
||||
|
||||
}
|
||||
public static FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex) {
|
||||
public static FillResult fillMask(Rng rng, Slot[] slots, Grid mask, DictEntry[] dictIndex) {
|
||||
val multiThreaded = Thread.currentThread().getName().contains("pool");
|
||||
val NO_LOG = (!Main.VERBOSE || multiThreaded);
|
||||
val grid = mask;
|
||||
@@ -919,7 +919,6 @@ public record SwedishGenerator(Rng rng, int[] stack) {
|
||||
val bitset = new long[2500];
|
||||
val undo = new long[64];
|
||||
|
||||
val slots = extractSlots(grid);
|
||||
val TOTAL = slots.length;
|
||||
val slotScores = new int[TOTAL];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user