introduce bitloops

This commit is contained in:
mike
2026-01-14 23:26:54 +01:00
parent 04e3844732
commit e8711b30a1
4 changed files with 10 additions and 23 deletions

View File

@@ -275,13 +275,6 @@ public record Export() {
if (letter == 0) return;
letterAt.put(idx, (char) (64 | letter));
});
/* for (var p : placed) {
for (var c : p.cells) {
if (clues.notClue(c) && g.lisLetterAt(c)) {
letterAt.put(c, (char) (64 | g.letter32At(c)));
}
}
}*/
// 4) render gridv2 over cropped bounds (out-of-bounds become '#')
var gridv2 = new String[Math.max(0, maxR - minR + 1)];

View File

@@ -287,12 +287,6 @@ public record SwedishGenerator(Rng rng, int[] stack, Clues cache) {
final byte[] g;
public long lo, hi;
static int offset(int r, int c) { return r | (c << 3); }
/// the pos will never target a clue
void setLetterLo(int idx, byte ch) {
lo |= (1L << idx);
g[idx] = ch;
}
}
static record DictEntry(long[] words, long[][] posBitsets, int length, int numlong) { }

View File

@@ -122,10 +122,10 @@ public class MainTest {
@Test
public void testCluesDeepCopy() {
var grid = Clues.createEmpty();
grid.setClue(Grid.offset(0, 0), (byte) 1);
grid.setClue(Grid.offset(0, 1), (byte) 2);
grid.setClue(Grid.offset(1, 0), (byte) 3);
grid.setClue(Grid.offset(1, 1), (byte) 0);
grid.setClue(OFF_0_0, (byte) 1);
grid.setClue(OFF_0_1, (byte) 2);
grid.setClue(OFF_1_0, (byte) 3);
grid.setClue(OFF_1_1, (byte) 0);
var copy = grid.deepCopyGrid();
Assertions.assertEquals((byte) 1, copy.digitAt(0));

View File

@@ -100,11 +100,11 @@ public class SwedishGeneratorTest {
@Test
void testPatternForSlotMixed() {
var grid = createEmpty();
grid.setLetterLo(OFF_0_0, LETTER_A);
grid.setLetterLo(OFF_2_0, LETTER_C);
placeWord(grid, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
placeWord(grid, 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, key, 7L, 0L);
assertEquals(1L | (0L) | (55L << 16), pattern);
assertEquals(1L | (55L << 16), pattern);
}
@Test
@@ -118,7 +118,7 @@ public class SwedishGeneratorTest {
@Test
void testPatternForSlotSingleLetter() {
var grid = createEmpty();
grid.setLetterLo(OFF_0_0, LETTER_A);
placeWord(grid, Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
var key = Slot.packSlotKey(1, CLUE_RIGHT);
var pattern = patternForSlot(grid, key, 7L, 0L);
assertEquals(1L, pattern);
@@ -144,7 +144,7 @@ public class SwedishGeneratorTest {
@Test
void testGrid() {
var grid = new Gridded(createEmpty());
grid.grid().setLetterLo(OFF_0_0, LETTER_A);
placeWord(grid.grid(), Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_0, 0, Lemma.from(0, "A"));
val arr = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
assertEquals(1, arr.size());
assertEquals(LETTER_A, arr.get(OFF_0_0));
@@ -310,7 +310,7 @@ public class SwedishGeneratorTest {
// 4. Partial placement then conflict (rollback)
grid = new Gridded(createEmpty());
grid.grid().setLetterLo(OFF_0_2, LETTER_X); // Conflict at the end
placeWord(grid.grid(), Slot.packSlotKey(0, CLUE_RIGHT), 1L << OFF_0_2, 0, Lemma.from(0, "X")); // Conflict at the end
assertFalse(placeWord(grid.grid(), key, lo, hi, w1));
map = grid.stream(Clues.createEmpty()).collect(Collectors.toMap(LetterAt::index, LetterAt::letter));
assertEquals(1, map.size());