introduce bitloops
This commit is contained in:
@@ -87,14 +87,12 @@ public class SwedishGenerator {
|
||||
public static final Pick PICK_NOT_DONE = new Pick(null, null, 0);
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
public static final class FillStats {
|
||||
|
||||
public double simplicity;
|
||||
}
|
||||
|
||||
public static record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed, @Delegate FillStats stats) {
|
||||
public static record FillResult(boolean ok, long nodes, long backtracks, int lastMRV, long elapsed, FillStats stats) {
|
||||
|
||||
}
|
||||
|
||||
@@ -144,16 +142,17 @@ public class SwedishGenerator {
|
||||
static final long LETTER_MASK = (1L << 40) - 1; // low 40 bits
|
||||
static final long INDEX_MASK = (1L << 24) - 1; // 24 bits
|
||||
|
||||
static long pack(String word) { return pack(word.getBytes(US_ASCII)); }
|
||||
static long pack(int index, byte[] b) { return pack(b) | ((long) index << 40); }
|
||||
static long pack(String word) { return pack(word.getBytes(US_ASCII)); }
|
||||
static long packW(byte[] b) { return pack(b) /*| ((long) index << 40)*/; }
|
||||
static long pack(byte[] b) {
|
||||
long w = 0;
|
||||
for (var i = 0; i < b.length; i++) w |= ((long) b[i] & 31) << (i * 5);
|
||||
return w;
|
||||
}
|
||||
static public long from(int index, String word) { return pack(index, word.getBytes(US_ASCII)); }
|
||||
static byte byteAt(long word, int idx) { return (byte) ((word >>> (idx * 5)) & 0b11111); }
|
||||
static int length(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5) + 1; }
|
||||
static public long from(String word) { return packW(word.getBytes(US_ASCII)); }
|
||||
static byte byteAt(long word, int idx) { return (byte) ((word >>> (idx * 5)) & 0b11111); }
|
||||
static int length(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5) + 1; }
|
||||
static int length0(long word) { return ((63 - numberOfLeadingZeros(word & LETTER_MASK)) / 5); }
|
||||
static ThreadLocal<byte[]> BYTES = ThreadLocal.withInitial(() -> new byte[MAX_WORD_LENGTH]);
|
||||
public static String asWord(long word) {
|
||||
val len = Lemma.length(word);
|
||||
@@ -413,10 +412,10 @@ public class SwedishGenerator {
|
||||
|
||||
var tries = Math.min(MAX_TRIES_PER_SLOT, N);
|
||||
for (var t = 0; t < tries; t++) {
|
||||
double r = rng.nextFloat();
|
||||
var shardIndx = (int) (r * r * r * (N - 1));
|
||||
var w = entry.words[shardIndx];
|
||||
var lemIdx = Lemma.unpackIndex(w);
|
||||
double r = rng.nextFloat();
|
||||
var shardIdx = (int) (r * r * r * (N - 1));
|
||||
var w = entry.words[shardIdx];
|
||||
var lemIdx = Lemma.unpackIndex(w);
|
||||
if (Bit1029.get(used, lemIdx)) continue;
|
||||
low = glo;
|
||||
top = ghi;
|
||||
@@ -424,7 +423,7 @@ public class SwedishGenerator {
|
||||
|
||||
Bit1029.set(used, lemIdx);
|
||||
s.assign.w = w;
|
||||
s.assign.shardIdx = shardIndx;
|
||||
s.assign.shardIdx = shardIdx;
|
||||
if (backtrack(depth + 1)) return true;
|
||||
s.assign.w = X;
|
||||
Bit1029.clear(used, lemIdx);
|
||||
|
||||
Reference in New Issue
Block a user