introduce bitloops

This commit is contained in:
mike
2026-01-12 06:42:22 +01:00
parent b7b66b5cd6
commit f655f70ab8
5 changed files with 38 additions and 36 deletions

View File

@@ -108,7 +108,7 @@ public class SwedishGeneratorTest {
var l1 = new Lemma("APPLE");
Assertions.assertEquals(Lemma.pack("APPLE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(l1.word()));
assertEquals(5, l1.length());
assertEquals(5, Lemma.length(l1.word()));
assertEquals((byte) 'A', l1.byteAt(0));
assertEquals(1, l1.intAt(0));
@@ -120,7 +120,7 @@ public class SwedishGeneratorTest {
var entry3 = dict.index()[3];
assertEquals(1, entry3.words().length);
assertEquals(Lemma.pack("AXE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(entry3.words()[0].word()));
assertEquals(Lemma.pack("AXE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(entry3.words()[0]));
// Check pos indexing
// AXE: A at 0, X at 1, E at 2
@@ -276,7 +276,7 @@ public class SwedishGeneratorTest {
// r(i) and c(i) are used by placeWord.
var packedPos = ((long) Grid.offset(0, 0)) | (((long) Grid.offset(0, 1)) << 7) | (((long) Grid.offset(0, 2)) << 14);
var s = Slot.from(0, packedPos, 3);
var w1 = new Lemma("ABC");
var w1 = new Lemma("ABC").word();
var undoBuffer = new int[10];
// 1. Successful placement in empty grid
@@ -291,7 +291,7 @@ public class SwedishGeneratorTest {
assertEquals(0L, undoBuffer[1]); // 0 new characters placed
// 3. Conflict: place "ABD" where "ABC" is
var w2 = new Lemma("ABD");
var w2 = new Lemma("ABD").word();
assertFalse(placeWord(grid, s, w2, undoBuffer, 2));
// Verify grid is unchanged (still "ABC")
assertEquals('A', grid.byteAt(Grid.offset(0, 0)));
@@ -314,7 +314,7 @@ public class SwedishGeneratorTest {
// Slot at 0,1 length 2
var packedPos = ((long) Grid.offset(0, 1)) | (((long) Grid.offset(0, 2)) << 7);
var s = Slot.from((0 << 8) | (1 << 4) | 2, packedPos, 2);
var w = new Lemma("AZ");
var w = new Lemma("AZ").word();
var undoBuffer = new int[10];
var placed = placeWord(grid, s, w, undoBuffer, 0);