introduce bitloops
This commit is contained in:
@@ -175,7 +175,7 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
this.hi = hi;
|
this.hi = hi;
|
||||||
}
|
}
|
||||||
static Grid createEmpty() { return new Grid(new byte[SIZE], X, X); }
|
static Grid createEmpty() { return new Grid(new byte[SIZE], X, X); }
|
||||||
int digitAt(int index) { return g[index] - 48; }
|
int digitAt(int index) { return g[index] & ~48; }
|
||||||
public static int r(int offset) { return offset & 7; }
|
public static int r(int offset) { return offset & 7; }
|
||||||
public static int c(int offset) { return offset >>> 3; }
|
public static int c(int offset) { return offset >>> 3; }
|
||||||
static int offset(int r, int c) { return r | (c << 3); }
|
static int offset(int r, int c) { return r | (c << 3); }
|
||||||
@@ -344,37 +344,6 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int intersectSorted(int[] a, int aLen, int[] b, int bLen, int[] out) {
|
|
||||||
if (aLen == 0 || bLen == 0) return 0;
|
|
||||||
if (aLen < bLen >>> 4) {
|
|
||||||
int k = 0;
|
|
||||||
for (int i = 0; i < aLen; i++) {
|
|
||||||
int x = a[i];
|
|
||||||
if (Arrays.binarySearch(b, 0, bLen, x) >= 0) out[k++] = x;
|
|
||||||
}
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
if (bLen < aLen >>> 4) {
|
|
||||||
int k = 0;
|
|
||||||
for (int i = 0; i < bLen; i++) {
|
|
||||||
int 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static record Slot(int key, long packedPos) {
|
static record Slot(int key, long packedPos) {
|
||||||
|
|
||||||
@@ -428,7 +397,7 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
|
|
||||||
for (int i = 0; i < 65; i += 64) {
|
for (int i = 0; i < 65; i += 64) {
|
||||||
for (long bits = (i == 0 ? lo_cl : hi_cl); bits != X; bits &= bits - 1) {
|
for (long bits = (i == 0 ? lo_cl : hi_cl); bits != X; bits &= bits - 1) {
|
||||||
int clueIdx = i + Long.numberOfTrailingZeros(bits);
|
int clueIdx = i | Long.numberOfTrailingZeros(bits);
|
||||||
var d = grid.digitAt(clueIdx);
|
var d = grid.digitAt(clueIdx);
|
||||||
var nbrs16 = OFFSETS[d];
|
var nbrs16 = OFFSETS[d];
|
||||||
long packed = nbrs16.path()[clueIdx];
|
long packed = nbrs16.path()[clueIdx];
|
||||||
@@ -778,7 +747,6 @@ public record SwedishGenerator(Rng rng) {
|
|||||||
val multiThreaded = Thread.currentThread().getName().contains("pool");
|
val multiThreaded = Thread.currentThread().getName().contains("pool");
|
||||||
val grid = mask.deepCopyGrid();
|
val grid = mask.deepCopyGrid();
|
||||||
val used = new Bit1029();
|
val used = new Bit1029();
|
||||||
// val assigned = new HashMap<Integer, Lemma>();
|
|
||||||
|
|
||||||
long[] assigned = new long[BIGG];
|
long[] assigned = new long[BIGG];
|
||||||
val ctx = CTX.get();
|
val ctx = CTX.get();
|
||||||
|
|||||||
@@ -161,6 +161,37 @@ public class SwedishGeneratorTest {
|
|||||||
assertTrue(Slot.horiz(2)); // right
|
assertTrue(Slot.horiz(2)); // right
|
||||||
assertFalse(Slot.horiz(3)); // down
|
assertFalse(Slot.horiz(3)); // 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) {
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 0; i < aLen; i++) {
|
||||||
|
int x = a[i];
|
||||||
|
if (Arrays.binarySearch(b, 0, bLen, x) >= 0) out[k++] = x;
|
||||||
|
}
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
if (bLen < aLen >>> 4) {
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 0; i < bLen; i++) {
|
||||||
|
int 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
|
@Test
|
||||||
void testIntersectSorted() {
|
void testIntersectSorted() {
|
||||||
|
|||||||
Reference in New Issue
Block a user