introduce bitloops

This commit is contained in:
mike
2026-01-14 10:39:06 +01:00
parent cb2935e0f5
commit 66bd8193ef
4 changed files with 32 additions and 14 deletions

View File

@@ -285,6 +285,14 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
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 boolean lisLetterAt(int pos) {
if ((pos & 64) == 0)
return lisLetterAtLo(pos);
return lisLetterAtHi(pos);
}
public boolean lisLetterAtLo(int pos) { return (lo & (1L << pos)) != 0; }
public boolean lisLetterAtHi(int pos) { return (hi & (1L << (pos & 63))) != 0; }
void setLetterLo(int idx, byte ch) {
lo |= (1L << idx);
@@ -313,8 +321,11 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
hi &= ~(1L << (idx & 63));
}
void undoPlace(long maskLo, long 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));
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));*/
}
}