data: one trie for maps and dictionaries, one loader

The hash map served a single exact-match lookup that the trie already
answers, at the price of a second container, a second file loader with
its own drift, and a Str-to-UTF-8 conversion on every chain probe. The
files are small (kanji.dict is 7.5k lines), so the trie holds both.
trieopen validates keys and each space-separated value word against Str
and reports path:line; trielookup takes the Str every caller holds and
treats a nil trie as an unloaded map; trienew/trieput exist for tests.
The overflow guards on growth, Trie.root (always 0) and the per-language
init loop written twice are gone.
This commit is contained in:
2026-08-16 15:56:32 +09:00
parent eb0f88f764
commit c7718ece52
15 changed files with 206 additions and 609 deletions

28
dat.h
View File

@@ -57,31 +57,19 @@ struct Emit
Str dict;
};
typedef struct Hnode Hnode;
struct Hnode
{
int filled;
int next;
char *key;
int klen;
char *val;
int vlen;
};
typedef struct Tnode Tnode;
struct Tnode
{
char *val;
int vlen;
int child;
int sibling;
char c;
char *val;
int vlen;
};
typedef struct Trie Trie;
struct Trie
{
int root;
Tnode *nodes;
int n;
int cap;
@@ -94,16 +82,6 @@ enum
TrieExact,
};
typedef struct Hmap Hmap;
struct Hmap
{
int nbs;
int nsz;
int len;
int cap;
uchar *nodes;
};
typedef struct Lang Lang;
typedef struct Im Im;
struct Lang
@@ -115,7 +93,7 @@ struct Lang
void (*back)(Im*);
void (*dictq)(Im*);
Trie *map;
Hmap *dict;
Trie *dict;
};
struct Im