introduce bitloops
This commit is contained in:
@@ -82,7 +82,7 @@ public class SwedishGeneratorTest {
|
||||
grid.setLetterLo(0, LETTER_A);
|
||||
grid.setLetterLo(1, LETTER_B);
|
||||
grid.setLetterLo(2, LETTER_C);
|
||||
var key = 18 << Slot.BIT_FOR_DIR | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(18, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
assertEquals(1L | (28L << 8) | (55L << 16), pattern);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class SwedishGeneratorTest {
|
||||
var grid = createEmpty();
|
||||
grid.setLetterLo(OFF_0_0, LETTER_A);
|
||||
grid.setLetterLo(2, LETTER_C);
|
||||
var key = 1 << Slot.BIT_FOR_DIR | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(1, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
assertEquals(1L | (0L) | (55L << 16), pattern);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testPatternForSlotAllDashes() {
|
||||
var grid = createEmpty();
|
||||
var key = 1 << Slot.BIT_FOR_DIR | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(1 << Slot.BIT_FOR_DIR, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
assertEquals(0L, pattern);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class SwedishGeneratorTest {
|
||||
void testPatternForSlotSingleLetter() {
|
||||
var grid = createEmpty();
|
||||
grid.setLetterLo(OFF_0_0, LETTER_A);
|
||||
var key = 1 << Slot.BIT_FOR_DIR | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(1, CLUE_RIGHT);
|
||||
var pattern = patternForSlot(grid, key, 7L, 0L);
|
||||
assertEquals(1L, pattern);
|
||||
}
|
||||
@@ -164,12 +164,6 @@ 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]));
|
||||
|
||||
// Check pos indexing
|
||||
// AXE: A at 0, X at 1, E at 2
|
||||
/* assertTrue(entry3.pos()[0][0].size() > 0);
|
||||
assertTrue(entry3.pos()[1]['X' - 'A'].size() > 0);
|
||||
assertTrue(entry3.pos()[2]['E' - 'A'].size() > 0);*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,7 +172,7 @@ public class SwedishGeneratorTest {
|
||||
// key = (r << 8) | (c << 4) | d
|
||||
var offset = OFF_2_3;
|
||||
System.out.println("[DEBUG_LOG] Grid.offset(2, 3) = " + offset);
|
||||
var key = (offset << Slot.BIT_FOR_DIR) | (CLUE_DOWN);
|
||||
var key = Slot.packSlotKey(offset, CLUE_DOWN);
|
||||
System.out.println("[DEBUG_LOG] key = " + key);
|
||||
long lo = 0;
|
||||
// pos 0: (2, 5)
|
||||
@@ -203,54 +197,6 @@ public class SwedishGeneratorTest {
|
||||
assertTrue(Slot.horiz(CLUE_RIGHT)); // right
|
||||
assertFalse(Slot.horiz(CLUE_DOWN)); // down
|
||||
}
|
||||
static int intersectSorted(int[] a, int aLen, int[] b, int bLen, int[] out) {
|
||||
if (aLen == 0 || bLen == 0) return 0;
|
||||
if (aLen < bLen >>> 4) {
|
||||
var k = 0;
|
||||
for (var i = 0; i < aLen; i++) {
|
||||
var x = a[i];
|
||||
if (Arrays.binarySearch(b, 0, bLen, x) >= 0) out[k++] = x;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
if (bLen < aLen >>> 4) {
|
||||
var k = 0;
|
||||
for (var i = 0; i < bLen; i++) {
|
||||
var y = b[i];
|
||||
if (Arrays.binarySearch(a, 0, aLen, y) >= 0) out[k++] = y;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
int i = 0, j = 0, k = 0, x, y;
|
||||
while (i < aLen && j < bLen) {
|
||||
x = a[i];
|
||||
y = b[j];
|
||||
if (x == y) {
|
||||
out[k++] = x;
|
||||
i++;
|
||||
j++;
|
||||
} else if (x < y) i++;
|
||||
else j++;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIntersectSorted() {
|
||||
var buff = new int[10];
|
||||
var a = new int[]{ 1, 3, 5, 7, 9 };
|
||||
var b = new int[]{ 2, 3, 6, 7, 10 };
|
||||
|
||||
var count = intersectSorted(a, a.length, b, b.length, buff);
|
||||
assertEquals(2, count);
|
||||
assertEquals(3, buff[0]);
|
||||
assertEquals(7, buff[1]);
|
||||
|
||||
var c = new int[]{ 1, 2, 3 };
|
||||
var d = new int[]{ 4, 5, 6 };
|
||||
count = intersectSorted(c, c.length, d, d.length, buff);
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
static long packPattern(String s) {
|
||||
long p = 0;
|
||||
@@ -258,7 +204,7 @@ public class SwedishGeneratorTest {
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
var val = b[i] & 31;
|
||||
if (val != 0) {
|
||||
p |= (long) (i * 26 + val) << (i << 3);
|
||||
p |= (i * 26L + val) << (i << 3);
|
||||
}
|
||||
}
|
||||
return p;
|
||||
@@ -326,7 +272,7 @@ public class SwedishGeneratorTest {
|
||||
void testPlaceWord() {
|
||||
var grid = createEmpty();
|
||||
// Slot at OFF_0_0 length 3, horizontal (right)
|
||||
var key = (OFF_0_0 << Slot.BIT_FOR_DIR) | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_0) | (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
val hi = 0L;
|
||||
var w1 = ABC;
|
||||
@@ -362,7 +308,7 @@ public class SwedishGeneratorTest {
|
||||
void testBacktrackingHelpers() {
|
||||
var grid = createEmpty();
|
||||
// Slot at 0,1 length 2
|
||||
var key = (OFF_0_0 << Slot.BIT_FOR_DIR) | (CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2);
|
||||
var w = AZ;
|
||||
val low = grid.lo;
|
||||
@@ -387,8 +333,8 @@ public class SwedishGeneratorTest {
|
||||
assertTrue(Slot.increasing(CLUE_DOWN)); // Down
|
||||
assertFalse(Slot.increasing(CLUE_UP)); // Up
|
||||
|
||||
assertTrue(Slot.increasing((0) | CLUE_RIGHT));
|
||||
assertFalse(Slot.increasing((0) | CLUE_LEFT));
|
||||
assertTrue(Slot.increasing(Slot.packSlotKey(0, CLUE_RIGHT)));
|
||||
assertFalse(Slot.increasing(Slot.packSlotKey(0, CLUE_LEFT)));
|
||||
|
||||
// 2. Test slotScore
|
||||
val counts = new byte[SIZE];
|
||||
|
||||
Reference in New Issue
Block a user