introduce bitloops
This commit is contained in:
@@ -129,7 +129,6 @@ public record Export() {
|
||||
|
||||
static class Bit {
|
||||
|
||||
static long pack(int r, int c) { return (((long) r) << 32) ^ (c & 0xFFFFFFFFL); }
|
||||
long l1, l2;
|
||||
public boolean get(int bitIndex) {
|
||||
if ((bitIndex & 64) == 0) return (l1 & (1L << bitIndex)) != 0L;
|
||||
|
||||
@@ -64,7 +64,6 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
static final byte B0 = (byte) 0;
|
||||
static final byte B64 = (byte) 64;
|
||||
static final byte B48 = (byte) 48;
|
||||
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
|
||||
static final rci[] IT = Neighbors9x8.IT;
|
||||
static final int[][] MUTATE_RI = new int[SIZE][625];
|
||||
@@ -314,10 +313,8 @@ public record SwedishGenerator(Rng rng) {
|
||||
static Slot from(int key, long lo, long hi) { return new Slot(key, lo, hi); }
|
||||
|
||||
public int len() { return Long.bitCount(lo) + Long.bitCount(hi); }
|
||||
public int clueR() { return Grid.r((key >>> BIT_FOR_DIR)); }
|
||||
public int clueIndex() { return clueIndex(key); }
|
||||
public static int clueIndex(int key) { return key >>> BIT_FOR_DIR; }
|
||||
public int clueC() { return Grid.c((key >>> BIT_FOR_DIR)); }
|
||||
public static int dir(int key) { return key & 7; }
|
||||
public boolean horiz() { return horiz(key); }
|
||||
public boolean reversed() { return (key & 2) == 0; }
|
||||
|
||||
@@ -73,11 +73,11 @@ public class MainTest {
|
||||
|
||||
// Test set/get
|
||||
grid.setLetter(Grid.offset(0, 0), (byte) 'A');
|
||||
grid.setClue(Grid.offset(1, 2), (byte) '5');
|
||||
grid.setClue(Grid.offset(1, 2), (byte) '3');
|
||||
grid.setLetter(Grid.offset(2, 3), (byte) 'Z');
|
||||
|
||||
Assertions.assertEquals((byte) 'A', grid.byteAt(Grid.offset(0, 0)));
|
||||
Assertions.assertEquals((byte) '5', grid.byteAt(Grid.offset(1, 2)));
|
||||
Assertions.assertEquals((byte) '3', grid.byteAt(Grid.offset(1, 2)));
|
||||
Assertions.assertEquals((byte) 'Z', grid.byteAt(Grid.offset(2, 3)));
|
||||
Assertions.assertEquals(DASH, grid.byteAt(Grid.offset(1, 1)));
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MainTest {
|
||||
// Test isDigitAt
|
||||
Assertions.assertFalse(grid.isClue(0));
|
||||
Assertions.assertTrue(grid.isClue(Grid.offset(1, 2)));
|
||||
Assertions.assertEquals(5, grid.digitAt(Grid.offset(1, 2)));
|
||||
Assertions.assertEquals(3, grid.digitAt(Grid.offset(1, 2)));
|
||||
Assertions.assertFalse(grid.isClue(Grid.offset(2, 3)));
|
||||
Assertions.assertFalse(grid.isClue(Grid.offset(1, 1)));
|
||||
|
||||
|
||||
@@ -148,8 +148,7 @@ public class SwedishGeneratorTest {
|
||||
|
||||
var s = Slot.from(key, lo, 0L);
|
||||
System.out.println("[DEBUG_LOG] s.dir() = " + Slot.dir(s.key()));
|
||||
assertEquals(2, s.clueR());
|
||||
assertEquals(3, s.clueC());
|
||||
assertEquals(Grid.offset(2,3), s.clueIndex());
|
||||
assertEquals(3, Slot.dir(s.key()));
|
||||
assertFalse(s.horiz());
|
||||
var cells = s.walk().toArray();
|
||||
@@ -257,8 +256,7 @@ public class SwedishGeneratorTest {
|
||||
// However, the test run might be using default Config values if not properly overridden in the test environment.
|
||||
// If Actual was 8, it means MAX_WORD_LENGTH was at least 8.
|
||||
assertTrue(s.len() >= 2);
|
||||
assertEquals(0, s.clueR());
|
||||
assertEquals(0, s.clueC());
|
||||
assertEquals(0, s.clueIndex());
|
||||
assertEquals(2, Slot.dir(s.key()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user