introduce bitloops
This commit is contained in:
@@ -31,10 +31,7 @@ import static java.nio.charset.StandardCharsets.*;
|
||||
@SuppressWarnings("ALL")
|
||||
public record SwedishGenerator(Rng rng) {
|
||||
|
||||
record CandidateInfo(int[] indices, int count) {
|
||||
|
||||
public CandidateInfo(int n) { this(null, n); }
|
||||
}
|
||||
record CandidateInfo(int[] indices, int count) { }
|
||||
|
||||
// static final CandidateInfo[] CANDIDATES = IntStream.range(0, 10192 << 2).mapToObj(CandidateInfo::new).toArray(CandidateInfo[]::new);
|
||||
|
||||
@@ -57,8 +54,6 @@ public record SwedishGenerator(Rng rng) {
|
||||
static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
|
||||
static final int MIN_LEN = Config.MIN_LEN;
|
||||
static final int MIN_LEN7 = Config.MIN_LEN * 7;
|
||||
static final int CLUE_SIZE = Config.CLUE_SIZE;
|
||||
static final int SIMPLICITY_DEFAULT_SCORE = 2;
|
||||
static final int MAX_TRIES_PER_SLOT = Config.MAX_TRIES_PER_SLOT;
|
||||
static final char C_DASH = '\0';
|
||||
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
|
||||
@@ -70,11 +65,9 @@ public record SwedishGenerator(Rng rng) {
|
||||
static final byte B0 = (byte) 0;
|
||||
static final byte B64 = (byte) 64;
|
||||
static final byte B48 = (byte) 48;
|
||||
// Directions for '1'..'6'
|
||||
static final long[] OFFSETS_D_IDX = Neighbors9x8.OFFSET_D_IDX;
|
||||
static final nbrs_16[] OFFSETS_FOUR = Neighbors9x8.OFFSETS_FOUR;
|
||||
static final rci[] IT = Neighbors9x8.IT;
|
||||
static final long[] INBR8_PACKEDT = Neighbors9x8.NBR8_PACKED;
|
||||
static final int[][] MUTATE_RI = new int[SIZE][625];
|
||||
static final long[] NBR8_PACKED_LO = Neighbors9x8.NBR8_PACKED_LO;
|
||||
static final long[] NBR8_PACKED_HI = Neighbors9x8.NBR8_PACKED_HI;
|
||||
@@ -233,11 +226,13 @@ public record SwedishGenerator(Rng rng) {
|
||||
|
||||
static record DictEntry(long[] words, long[][] posBitsets) { }
|
||||
|
||||
public static record Lemma(long word) {
|
||||
static int LEMMA_COUNTER = 0;
|
||||
|
||||
public static interface Lemma {
|
||||
|
||||
static final long LETTER_MASK = (1L << 40) - 1; // low 40 bits
|
||||
static final long INDEX_MASK = (1L << 24) - 1; // 24 bits
|
||||
|
||||
static final long LETTER_MASK = (1L << 40) - 1; // low 40 bits
|
||||
static final long INDEX_MASK = (1L << 24) - 1; // 24 bits
|
||||
static int LEMMA_COUNTER = 0;
|
||||
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(byte[] b) {
|
||||
@@ -245,33 +240,20 @@ public record SwedishGenerator(Rng rng) {
|
||||
for (var i = 0; i < b.length; i++) w |= ((long) b[i] & ~64) << (i * 5);
|
||||
return w;
|
||||
}
|
||||
public Lemma(int index, String word) { this(pack(index, word.getBytes(US_ASCII))); }
|
||||
public Lemma(String word) { this(LEMMA_COUNTER++, word); }
|
||||
static public long from(String word) { return pack(LEMMA_COUNTER++, word.getBytes(US_ASCII)); }
|
||||
static byte byteAt(long word, int idx) { return (byte) ((word >>> (idx * 5)) & 0b11111 | B64); }// word[]; }
|
||||
static int intAt(long word, int idx) { return (int) (((word >>> (idx * 5))) & 0b11111); }// word[]; }
|
||||
static String[] clue(long w) { return CsvIndexService.clues(unpackIndex(w)); }
|
||||
static int simpel(long w) { return CsvIndexService.simpel(unpackIndex(w)); }
|
||||
static int length(long word) {
|
||||
if (word == 0) return 0;
|
||||
int highestBit = 63 - Long.numberOfLeadingZeros(word & LETTER_MASK);
|
||||
return (highestBit / 5) + 1;
|
||||
}
|
||||
static int usedCharsInPattern(long p) {
|
||||
if (p == 0) return 0;
|
||||
int highestBit = 63 - Long.numberOfLeadingZeros(p & LETTER_MASK); // 0-based
|
||||
return (highestBit / 5) + 1;
|
||||
}
|
||||
static int length(long word) { return ((63 - Long.numberOfLeadingZeros(word & LETTER_MASK)) / 5) + 1; }
|
||||
static int usedCharsInPattern(long p) { return ((63 - Long.numberOfLeadingZeros(p & LETTER_MASK)) / 5) + 1; }
|
||||
public static String asWord(long word) {
|
||||
var b = new byte[Lemma.length(word)];
|
||||
for (var i = 0; i < b.length; i++) b[i] = (byte) ((word >>> (i * 5)) & 0b11111 | B64);
|
||||
return new String(b, US_ASCII);
|
||||
}
|
||||
static int unpackIndex(long w) {
|
||||
return (int) (w >>> 40);
|
||||
}
|
||||
static int unpackLetters(long w) {
|
||||
return (int) (w & LETTER_MASK);
|
||||
}
|
||||
static int unpackIndex(long w) { return (int) (w >>> 40); }
|
||||
static int unpackLetters(long w) { return (int) (w & LETTER_MASK); }
|
||||
}
|
||||
|
||||
public static record Dict(
|
||||
|
||||
Reference in New Issue
Block a user