introduce bitloops

This commit is contained in:
mike
2026-01-12 09:42:13 +01:00
parent 84e832df40
commit 67eedb773b
3 changed files with 32 additions and 50 deletions

View File

@@ -101,19 +101,19 @@ public class SwedishGeneratorTest {
@Test
void testLemmaAndDict() {
var l2a = new Lemma("IN").word();
var l4a = new Lemma("INER").word();
var l6a = new Lemma("INEREN").word();
var l7a = new Lemma("INERENA").word();
var l8a = new Lemma("INERENAE").word();
var l2a = Lemma.from("IN");
var l4a = Lemma.from("INER");
var l6a = Lemma.from("INEREN");
var l7a = Lemma.from("INERENA");
var l8a = Lemma.from("INERENAE");
var l1 = new Lemma("APPLE").word();
var l1 = Lemma.from("APPLE");
Assertions.assertEquals(Lemma.pack("APPLE".getBytes(StandardCharsets.US_ASCII)), Lemma.unpackLetters(l1));
assertEquals(5, Lemma.length(l1));
assertEquals((byte) 'A', Lemma.byteAt(l1, 0));
assertEquals(1, Lemma.intAt(l1, 0));
var l2 = new Lemma("AXE").word();
var l2 = Lemma.from("AXE");
var dict = new Dict(new long[]{ l1, l2, l2a, l4a, l6a, l7a, l8a });
assertEquals(1, dict.index()[3].words().length);
@@ -213,15 +213,15 @@ public class SwedishGeneratorTest {
@Test
void testCandidateInfoForPattern() {
var l0 = new Lemma("IN").word();
var l3a = new Lemma("INE").word();
var l4a = new Lemma("INER").word();
var l6a = new Lemma("INEREN").word();
var l7a = new Lemma("INERENA").word();
var l8a = new Lemma("INERENAE").word();
var l1 = new Lemma("APPLE").word();
var l2 = new Lemma("APPLY").word();
var l3 = new Lemma("BANAN").word();
var l0 = Lemma.from("IN");
var l3a = Lemma.from("INE");
var l4a = Lemma.from("INER");
var l6a = Lemma.from("INEREN");
var l7a = Lemma.from("INERENA");
var l8a = Lemma.from("INERENAE");
var l1 = Lemma.from("APPLE");
var l2 = Lemma.from("APPLY");
var l3 = Lemma.from("BANAN");
var dict = new Dict(new long[]{ l0, l1, l2, l3, l3a, l4a, l6a, l7a, l8a });
// Pattern "APP--" for length 5
@@ -309,7 +309,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").word();
var w1 = Lemma.from("ABC");
var undoBuffer = new int[10];
// 1. Successful placement in empty grid
@@ -324,7 +324,7 @@ public class SwedishGeneratorTest {
assertEquals(0L, undoBuffer[1]); // 0 new characters placed
// 3. Conflict: place "ABD" where "ABC" is
var w2 = new Lemma("ABD").word();
var w2 = Lemma.from("ABD");
assertFalse(placeWord(grid, s, w2, undoBuffer, 2));
// Verify grid is unchanged (still "ABC")
assertEquals('A', grid.byteAt(Grid.offset(0, 0)));
@@ -347,7 +347,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").word();
var w = Lemma.from("AZ");
var undoBuffer = new int[10];
var placed = placeWord(grid, s, w, undoBuffer, 0);