trie: one node per rune, children in rune order, and the last path kept

The trie walked a key byte by byte, so a Hangul syllable cost three
nodes and every lookup first spelled its key back into UTF-8.  It walks
runes now: a third of the nodes for Korean data, and no buffer in the
lookup.  Children are kept in rune order, so both the search and the
insert stop early, and a trie remembers the path of the last key put,
which a file sorted by key — hanja.dict is one — walks straight down.
This commit is contained in:
2026-08-17 12:50:05 +09:00
parent 6a6749e824
commit 3527bcd489
3 changed files with 41 additions and 24 deletions

5
dat.h
View File

@@ -74,7 +74,7 @@ struct Tnode
int vlen;
int child;
int sibling;
char c;
Rune c;
};
typedef struct Trie Trie;
@@ -83,6 +83,9 @@ struct Trie
Tnode *nodes;
int n;
int cap;
/* the last key put and its path, so a sorted file walks it once */
Str last;
int path[Maxrunes];
};
enum