@@ -22,7 +22,31 @@ export declare class WordlistEngine {
2222 private nextSeq ;
2323 private readonly DB_NAME ;
2424 private readonly DB_VERSION ;
25- private readonly STORE_NAME ;
25+ /** ~800 chunk records covering the whole wordlist, keyed by firstWord */
26+ private readonly CHUNK_STORE ;
27+ /** Row-per-entry store for Morpheus-analyzed unknown words (small, grows
28+ * incrementally — the chunk layout is immutable after load) */
29+ private readonly EXTRA_STORE ;
30+ /** Single meta record: schema/data version + entry count */
31+ private readonly META_STORE ;
32+ /** Bump when the packing logic changes incompatibly. */
33+ private readonly SCHEMA_VERSION ;
34+ /** Bump when macrons.txt content changes, so returning visitors reload
35+ * instead of keeping a stale dictionary forever. */
36+ private readonly DATA_VERSION ;
37+ /** Entries per chunk. 1000 keeps a chunk ~100KB — one get() per unseen
38+ * wordform neighborhood, small enough to clone cheaply. */
39+ private readonly CHUNK_SIZE ;
40+ /** Sorted chunk keys, loaded once per session (~800 strings). */
41+ private chunkKeys ;
42+ /** Fetched chunks by firstWord — bounded by chunk count (~800); cleared in
43+ * clearEntriesCache() together with the per-word cache. */
44+ private chunksCache ;
45+ /** Full in-memory groups map, present only in the session that parsed the
46+ * file. Serves lookups instantly while chunks persist in the background. */
47+ private memGroups ;
48+ /** Resolves when the background chunk persist finishes (tests await this). */
49+ private persistPromise ;
2650 /** Cache of Morpheus analyses by normalized wordform (for UI display) */
2751 private morpheusCache ;
2852 /** In-memory cache for getAllEntries — eliminates redundant IndexedDB cursor
@@ -33,8 +57,11 @@ export declare class WordlistEngine {
3357 * Initialize IndexedDB database
3458 */
3559 init ( ) : Promise < void > ;
60+ private idbGet ;
3661 /**
37- * Check if database is populated
62+ * Check if database is populated with the current schema+data version.
63+ * A stale version (schema change or updated macrons.txt) reads as empty,
64+ * which makes the caller re-download and overwrite.
3865 */
3966 isPopulated ( ) : Promise < boolean > ;
4067 /**
@@ -53,20 +80,33 @@ export declare class WordlistEngine {
5380 * Returns entries with accentedUnderscore populated
5481 */
5582 getAllEntries ( wordform : string ) : Promise < WordlistEntry [ ] > ;
83+ /** Binary search the sorted chunk keys for the chunk that could contain
84+ * `word` (greatest firstWord <= word), fetch it, and read the group. */
85+ private lookupInChunks ;
86+ private lookupInExtras ;
5687 /**
5788 * Normalize tag format (convert dots to dashes for consistency with RFTagger)
5889 */
5990 private normalizeTag ;
6091 /**
61- * Add single entry to wordlist
92+ * Add single entry (Morpheus-analyzed unknown word). Goes to the extras
93+ * store — the chunk layout is immutable after the bulk load, and extras
94+ * only ever exist for words the wordlist file doesn't contain.
6295 */
6396 addEntry ( entry : WordlistEntry ) : Promise < void > ;
97+ /** Normalize a parsed file entry once, before grouping. */
98+ private normalizeEntry ;
99+ /** Group entries by wordform, preserving file order within each group —
100+ * the same order the old (wordform, seq) index cursor produced. */
101+ private buildGroups ;
64102 /**
65- * Batch add entries (for file loading)
103+ * Batch add entries (for file loading). Packs the wordlist into ~800
104+ * sorted range chunks instead of 812k individual rows — measured ~20x
105+ * faster to persist, and lookups become one direct get() per chunk.
66106 */
67107 addEntries ( entries : WordlistEntry [ ] , onProgress ?: ( count : number ) => void ) : Promise < void > ;
68108 /**
69- * Clear all entries
109+ * Clear all stores
70110 */
71111 clear ( ) : Promise < void > ;
72112 /**
@@ -87,6 +127,9 @@ export declare class WordlistEngine {
87127 * e.g. "a\te--------\ta\ta_"
88128 */
89129 loadFromText ( text : string , onProgress ?: ( count : number ) => void ) : Promise < void > ;
130+ /** Await the background chunk persist (no-op if none is running). Lets
131+ * tests and shutdown paths ensure durability before closing the page. */
132+ flush ( ) : Promise < void > ;
90133 /**
91134 * Load wordlist from URL (fetch + parse)
92135 */
0 commit comments