Gather data
This commit is contained in:
@@ -90,7 +90,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
IntList[] intListBuffer,
|
||||
long[] undoBuffer) {
|
||||
|
||||
public Context() { this(new int[256], new int[256], new int[256], new int[256], new BitSet(256), new char[32], new IntList[32], new long[2048]); }
|
||||
public Context() { this(new int[256], new int[256], new int[256], new int[256], new BitSet(256), new char[32], new IntList[32], new long[2048]); }
|
||||
void setPatter(char[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
|
||||
}
|
||||
|
||||
static final class Rng {
|
||||
@@ -120,8 +121,8 @@ public record SwedishGenerator(int[] buff) {
|
||||
record Grid(byte[] g) {
|
||||
|
||||
Grid deepCopyGrid() { return new Grid(g.clone()); }
|
||||
private int offset(int r, int c) { return r * W + c; }
|
||||
boolean isLettercell(int r, int c) { return !isDigitAt(r, c); }
|
||||
private int offset(int r, int c) { return r | (c << 3); }
|
||||
boolean isLettercell(int r, int c) { return (g[offset(r, c)] & 48) != 48; }
|
||||
char getCharAt(int r, int c) { return (char) (g[offset(r, c)]); }
|
||||
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
|
||||
byte byteAt(int r, int c) { return g[offset(r, c)]; }
|
||||
@@ -176,15 +177,15 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
}
|
||||
|
||||
static record Lemma(int index, String word, int length, int simpel, ArrayList<String> clue) {
|
||||
static record Lemma(int index, char[] word, int simpel, ArrayList<String> clue) {
|
||||
|
||||
static int LEMMA_COUNTER = 0;
|
||||
public Lemma(int index, String word, int simpel, String clu) {
|
||||
this(index, word, word.length(), simpel, new ArrayList<String>(10));
|
||||
this(index, word.toCharArray(), simpel, new ArrayList<String>(10));
|
||||
clue.add(clu);
|
||||
}
|
||||
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
|
||||
char charAt(int idx) { return word.charAt(idx); }
|
||||
char charAt(int idx) { return word[idx]; }
|
||||
@Override public int hashCode() { return index; }
|
||||
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
|
||||
}
|
||||
@@ -197,12 +198,12 @@ public record SwedishGenerator(int[] buff) {
|
||||
Lemma[] lemmas = wordz.clone();
|
||||
Arrays.sort(lemmas, Comparator.comparingInt(wd -> wd.simpel));
|
||||
|
||||
var lenCounts = new int[12];
|
||||
var index = new DictEntry[12];
|
||||
var lenCounts = new int[MAX_WORD_LENGTH+1];
|
||||
var index = new DictEntry[MAX_WORD_LENGTH+1];
|
||||
Arrays.setAll(index, i -> new DictEntry(i));
|
||||
int maxLength = -1;
|
||||
for (var lemma : lemmas) {
|
||||
var L = lemma.length();
|
||||
var L = lemma.word.length;
|
||||
if (L > maxLength) maxLength = L;
|
||||
lenCounts[L]++;
|
||||
|
||||
@@ -282,10 +283,10 @@ public record SwedishGenerator(int[] buff) {
|
||||
return Arrays.copyOf(buff, k);
|
||||
}
|
||||
|
||||
CandidateInfo candidateInfoForPattern(DictEntry entry, char[] pattern, int len) {
|
||||
var ctx = CTX.get();
|
||||
var listBuffer = ctx.intListBuffer;
|
||||
int listCount = 0;
|
||||
CandidateInfo candidateInfoForPattern(Context ctx, DictEntry entry, int len) {
|
||||
char[] pattern = ctx.pattern;
|
||||
var listBuffer = ctx.intListBuffer;
|
||||
int listCount = 0;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var ch = pattern[i];
|
||||
if (isLetter(ch)) {
|
||||
@@ -362,8 +363,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
long packedCs = 0;
|
||||
var n = 0;
|
||||
|
||||
while (rr >= 0 && rr < H && cc >= 0 && cc < W && n < MAX_WORD_LENGTH) {
|
||||
if (grid.isDigitAt(rr, cc)) break;
|
||||
while (rr >= 0 && rr < H && cc >= 0 && cc < W && grid.isLettercell(rr, cc) && n < MAX_WORD_LENGTH) {
|
||||
packedRs |= (long) rr << (n << 2);
|
||||
packedCs |= (long) cc << (n << 2);
|
||||
n++;
|
||||
@@ -772,7 +772,7 @@ public record SwedishGenerator(int[] buff) {
|
||||
}
|
||||
|
||||
var patLen = patternForSlot(grid, s, ctx.pattern);
|
||||
var info = candidateInfoForPattern(entry, ctx.pattern, patLen);
|
||||
var info = candidateInfoForPattern(ctx, entry, patLen);
|
||||
|
||||
if (info.count == 0) {
|
||||
return new Pick(null, null, false);
|
||||
|
||||
Reference in New Issue
Block a user