Gather data

This commit is contained in:
mike
2026-01-09 02:47:24 +01:00
parent 5abbee5396
commit adb05e1516
4 changed files with 38 additions and 48 deletions

View File

@@ -188,7 +188,7 @@ public record ExportFormat() {
public record WordOut(Lemma lemma, int startRow, int startCol, String direction, int arrowRow, int arrowCol, boolean isReversed, int complex) {
public String word() { return new String(lemma().word()); }
public String word() { return new String(lemma().word(), java.nio.charset.StandardCharsets.US_ASCII); }
public ArrayList<String> clue() { return lemma.clue(); }
}

View File

@@ -51,7 +51,7 @@ public record SwedishGenerator(int[] buff) {
static final char C_DASH = '\0';
static final byte _1 = 49, _9 = 57, A = 65, Z = 90, DASH = (byte) C_DASH;
static final ThreadLocal<Context> CTX = ThreadLocal.withInitial(Context::new);
static boolean isLetter(char ch) { return ch >= 'A' && ch <= 'Z'; }
static boolean isLetter(byte b) { return b >= 'A' && b <= 'Z'; }
static int clamp(int x, int a, int b) { return Math.max(a, Math.min(b, x)); }
public SwedishGenerator() { this(new int[8124]); }
@@ -88,15 +88,15 @@ public record SwedishGenerator(int[] buff) {
int[] cellCount,
int[] stack,
Bit seen,
char[] pattern,
byte[] pattern,
IntList[] intListBuffer,
int[] undoBuffer) {
public Context() {
this(new int[SIZE], new int[SIZE], new int[SIZE], new int[SIZE], new Bit(), new char[MAX_WORD_LENGTH], new IntList[MAX_WORD_LENGTH],
this(new int[SIZE], new int[SIZE], new int[SIZE], new int[SIZE], new Bit(), new byte[MAX_WORD_LENGTH], new IntList[MAX_WORD_LENGTH],
new int[2048]);
}
void setPatter(char[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
void setPatter(byte[] chars) { System.arraycopy(chars, 0, this.pattern, 0, chars.length); }
}
static final class Rng {
@@ -131,6 +131,7 @@ public record SwedishGenerator(int[] buff) {
static final byte _48 = 48;
record Grid(byte[] g) {
int digitAt(int r, int c) { return g[offset(r, c)] - 48; }
public static int r(int offset) { return offset & 7; }
public static int c(int offset) { return offset >>> 3; }
@@ -202,15 +203,15 @@ public record SwedishGenerator(int[] buff) {
}
}
static record Lemma(int index, char[] word, int simpel, ArrayList<String> clue) {
static record Lemma(int index, byte[] word, int simpel, ArrayList<String> clue) {
static int LEMMA_COUNTER = 0;
public Lemma(int index, String word, int simpel, String clu) {
this(index, word.toCharArray(), simpel, new ArrayList<String>(10));
this(index, word.getBytes(StandardCharsets.US_ASCII), 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[idx]; }
byte byteAt(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); }
}
@@ -237,7 +238,7 @@ public record SwedishGenerator(int[] buff) {
entry.words.add(lemma);
for (var i = 0; i < L; i++) {
var letter = lemma.charAt(i) - 'A';
var letter = lemma.byteAt(i) - 'A';
if (letter >= 0 && letter < 26) entry.pos[i][letter].add(idx);
else throw new RuntimeException("Illegal letter: " + letter + " in word " + lemma);
}
@@ -788,10 +789,10 @@ public record SwedishGenerator(int[] buff) {
}
}
static void patternForSlot(Grid grid, Slot s, char[] pat) {
static void patternForSlot(Grid grid, Slot s, byte[] pat) {
for (var i = 0; i < s.len(); i++) {
var ch = grid.getCharAt(s.pos(i));
pat[i] = isLetter(ch) ? ch : C_DASH;
var ch = grid.byteAt(s.pos(i));
pat[i] = isLetter(ch) ? ch : DASH;
}
}
@@ -803,12 +804,12 @@ public record SwedishGenerator(int[] buff) {
static int placeWord(Grid grid, Slot s, Lemma w, int[] undoBuffer, int offset) {
int mask = 0;
for (var i = 0; i < s.len(); i++) {
int idx = s.pos(i);
char cur = grid.getCharAt(idx);
var ch = w.charAt(i);
int idx = s.pos(i);
var cur = grid.byteAt(idx);
var ch = w.byteAt(i);
if (cur == C_DASH) {
mask |= (1 << i);
grid.setCharAt(idx, ch);
grid.setByteAt(idx, ch);
} else if (cur != ch) {
for (var j = 0; j < i; j++) {
if ((mask & (1 << j)) != 0) {
@@ -922,7 +923,7 @@ public record SwedishGenerator(int[] buff) {
var k = s.key();
int patLen = s.len();
var entry = dictIndex[patLen];
var pat = new char[patLen];
var pat = new byte[patLen];
patternForSlot(grid, s, pat);
if (pick.info.indices != null && pick.info.indices.length > 0) {
var idxs = pick.info.indices;
@@ -939,7 +940,7 @@ public record SwedishGenerator(int[] buff) {
boolean match = true;
for (var i = 0; i < patLen; i++) {
if (pat[i] != C_DASH && pat[i] != w.charAt(i)) {
if (pat[i] != DASH && pat[i] != w.byteAt(i)) {
match = false;
break;
}
@@ -978,7 +979,7 @@ public record SwedishGenerator(int[] buff) {
boolean match = true;
for (var i = 0; i < patLen; i++) {
if (pat[i] != C_DASH && pat[i] != w.charAt(i)) {
if (pat[i] != C_DASH && pat[i] != w.byteAt(i)) {
match = false;
break;
}