introduce bitloops

This commit is contained in:
mike
2026-01-10 10:10:31 +01:00
parent 948ba91467
commit 00c6f387a2
2 changed files with 13 additions and 15 deletions

View File

@@ -63,8 +63,8 @@
</dependency>
<dependency>
<groupId>mike.processor</groupId>
<artifactId>puzzle-processor</artifactId>
<version>1.4-SNAPSHOT</version>
<artifactId>puzzle-processor</artifactId>
<version>1.7-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -104,7 +104,7 @@
<path>
<groupId>mike.processor</groupId>
<artifactId>puzzle-processor</artifactId>
<version>1.4-SNAPSHOT</version>
<version>1.7-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
<source>25</source>

View File

@@ -47,8 +47,10 @@ public record SwedishGenerator(Rng rng) {
static final double SIZED = (double) SIZE;// ~18
static final int TARGET_CLUES = SIZE >> 2;
static final int MAX_WORD_LENGTH = C <= R ? C : R;
static final int MAX_WORD_LENGTH7 = MAX_WORD_LENGTH * 7;
static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
static final int MIN_LEN = Config.MIN_LEN;
static final int MIN_LEN7 = Config.MIN_LEN * 7;
static final int CLUE_SIZE = Config.CLUE_SIZE;
static final int SIMPLICITY_DEFAULT_SCORE = 2;
static final int MAX_TRIES_PER_SLOT = Config.MAX_TRIES_PER_SLOT;
@@ -218,10 +220,6 @@ public record SwedishGenerator(Rng rng) {
}
int clueCount() { return Long.bitCount(bo[0]) + Long.bitCount(bo[1]); }
void forEachSetBit71(IntConsumer consumer) {
for (var lo = bo[0]; lo != 0; lo &= lo - 1) consumer.accept(Long.numberOfTrailingZeros(lo));
for (var hi = bo[1]; hi != 0; hi &= hi - 1) consumer.accept(64 + Long.numberOfTrailingZeros(hi));
}
void forEachSlot(SlotVisitor visitor) {
for (var lo = bo[0]; lo != 0; lo &= lo - 1) processSlot(this, visitor, Long.numberOfTrailingZeros(lo));
for (var hi = bo[1]; hi != 0; hi &= hi - 1) processSlot(this, visitor, 64 + Long.numberOfTrailingZeros(hi));
@@ -414,16 +412,16 @@ public record SwedishGenerator(Rng rng) {
var d = grid.digitAt(clueIdx);
var nbrs16 = OFFSETS[d];
long packed = nbrs16.path()[clueIdx];
int n = (int) (packed >>> 56), k, idx;
int n = (int) (packed >>> 56) * 7, k, idx;
var horiz = Slot.horiz(d) ? covH : covV;
for (k = 0; k < n && k < MAX_WORD_LENGTH; k++) {
idx = (int) ((packed >>> (k * 7)) & 0x7F);
for (k = 0; k < n && k < MAX_WORD_LENGTH7; k += 7) {
idx = (int) ((packed >>> (k)) & 0x7F);
if (grid.isClue(idx)) break;
horiz[idx] += 1;
}
if (k == 0) return;
hasSlots = true;
if (k < MIN_LEN) penalty += 8000;
if (k < MIN_LEN7) penalty += 8000;
}
void clueStackPenalty(int clueIdx) {
@@ -435,9 +433,9 @@ public record SwedishGenerator(Rng rng) {
for (int sp = 1, n, nidx, k; sp > 0; size++) {
packed = Neighbors9x8.NBR8_PACKED[stack[--sp]];
n = (int) (packed >>> 56);
for (k = 0; k < n; k++) {
nidx = (int) ((packed >>> (k * 7)) & 0x7F);
n = (int) (packed >>> 56) * 7;
for (k = 0; k < n; k += 7) {
nidx = (int) ((packed >>> k) & 0x7F);
if (seen.get(nidx) || grid.notClue(nidx)) continue;
seen.set(nidx);
stack[sp++] = nidx;
@@ -520,7 +518,7 @@ public record SwedishGenerator(Rng rng) {
long bo0 = out.bo[0], bo1 = out.bo[1];
for (var rci : IT) {
int i = rci.i();
if ((rci.r() - CROSS_C) * nc + (rci.c() - CROSS_R) * nr < 0) {
if ((rci.cross_r()) * nc + (rci.cross_c()) * nr < 0) {
byte ch = b.g[i];
if (out.g[i] != ch) {
out.g[i] = ch;