Gather data

This commit is contained in:
mike
2026-01-09 21:55:34 +01:00
parent 95891d9efe
commit 2ec023b49d
2 changed files with 19 additions and 21 deletions

View File

@@ -248,7 +248,7 @@ public class Main {
var tLoad1 = System.nanoTime(); var tLoad1 = System.nanoTime();
section("Load"); section("Load");
info(String.format(Locale.ROOT, "words : %,d", dict.wordz().length)); info(String.format(Locale.ROOT, "words : %,d", dict.dictLength() ));
info(String.format(Locale.ROOT, "loadTime : %.3f s", (tLoad1 - tLoad0) / 1e9)); info(String.format(Locale.ROOT, "loadTime : %.3f s", (tLoad1 - tLoad0) / 1e9));
section("Search"); section("Search");
@@ -332,7 +332,7 @@ public class Main {
if (TOTAL_SUCCESS.get() > 0) { if (TOTAL_SUCCESS.get() > 0) {
info(String.format(Locale.ROOT, "avgSimplic : %.2f", TOTAL_SIMPLICITY.get() / 100.0 / TOTAL_SUCCESS.get())); info(String.format(Locale.ROOT, "avgSimplic : %.2f", TOTAL_SIMPLICITY.get() / 100.0 / TOTAL_SUCCESS.get()));
} }
info(String.format(Locale.ROOT, "dictWords : %,d", dict.wordz().length)); info(String.format(Locale.ROOT, "dictWords : %,d", dict.dictLength()));
return resFinal; return resFinal;
} }

View File

@@ -40,7 +40,8 @@ public record SwedishGenerator() {
static final int SIZE = C * R;// ~18 static final int SIZE = C * R;// ~18
static final double SIZED = (double) SIZE;// ~18 static final double SIZED = (double) SIZE;// ~18
static final int TARGET_CLUES = SIZE >> 2; static final int TARGET_CLUES = SIZE >> 2;
static final int MAX_WORD_LENGTH = Math.min(C, R); static final int MAX_WORD_LENGTH = C <= R ? C : R;
static final int MAX_WORD_LENGTH_PLUS_ONE = MAX_WORD_LENGTH + 1;
static final int MIN_LEN = Config.MIN_LEN; static final int MIN_LEN = Config.MIN_LEN;
static final int CLUE_SIZE = Config.CLUE_SIZE; static final int CLUE_SIZE = Config.CLUE_SIZE;
static final int SIMPLICITY_DEFAULT_SCORE = 2; static final int SIMPLICITY_DEFAULT_SCORE = 2;
@@ -269,28 +270,24 @@ public record SwedishGenerator() {
static record Lemma(int index, byte[] word, int simpel, String[] clue) { static record Lemma(int index, byte[] word, int simpel, String[] clue) {
static int LEMMA_COUNTER = 0; static int LEMMA_COUNTER = 0;
public Lemma(int index, String word, int simpel, String[] clu) { public Lemma(int index, String word, int simpel, String[] clu) { this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu); }
this(index, word.getBytes(StandardCharsets.US_ASCII), simpel, clu); public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, new String[]{ clue }); }
} public Lemma(String word, int simpel, String[] clue) { this(LEMMA_COUNTER++, word, simpel, clue); }
public Lemma(String word, int simpel, String clue) { this(LEMMA_COUNTER++, word, simpel, new String[]{ clue }); } byte byteAt(int idx) { return word[idx]; }
public Lemma(String word, int simpel, String[] clue) { this(LEMMA_COUNTER++, word, simpel, clue); } @Override public int hashCode() { return index; }
byte byteAt(int idx) { return word[idx]; } @Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
@Override public int hashCode() { return index; }
@Override public boolean equals(Object o) { return (o == this) || (o instanceof Lemma l && l.index == index); }
} }
public static record Dict(Lemma[] wordz, public static record Dict(
DictEntry[] index, DictEntry[] index,
int[] lenCounts) { int[] lenCounts) {
public Dict(Lemma[] wordz) { public Dict(Lemma[] wordz) {
var lenCounts = new int[MAX_WORD_LENGTH + 1]; var lenCounts = new int[MAX_WORD_LENGTH_PLUS_ONE];
var index = new DictEntry[MAX_WORD_LENGTH + 1]; var index = new DictEntry[MAX_WORD_LENGTH_PLUS_ONE];
Arrays.setAll(index, i -> new DictEntry(i)); Arrays.setAll(index, i -> new DictEntry(i));
int maxLength = -1;
for (var lemma : wordz) { for (var lemma : wordz) {
var L = lemma.word.length; var L = lemma.word.length;
if (L > maxLength) maxLength = L;
lenCounts[L]++; lenCounts[L]++;
var entry = index[L]; var entry = index[L];
@@ -299,12 +296,13 @@ public record SwedishGenerator() {
for (var i = 0; i < L; i++) { for (var i = 0; i < L; i++) {
var letter = lemma.byteAt(i) - 'A'; var letter = lemma.byteAt(i) - 'A';
if (letter >= 0 && letter < 26) entry.pos[i][letter].add(idx); if (letter < 0 || letter >= 26) throw new RuntimeException("Illegal letter: " + letter + " in word " + lemma);
else throw new RuntimeException("Illegal letter: " + letter + " in word " + lemma); entry.pos[i][letter].add(idx);
} }
} }
this(wordz, index, lenCounts); this(index, lenCounts);
} }
public int dictLength() { return Arrays.stream(lenCounts).sum(); }
} }
static final Gson GSON = new Gson(); static final Gson GSON = new Gson();