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

2
dict.c
View File

@@ -24,7 +24,7 @@ words(Tnode *nd, Str *out, int n, int max)
return n;
}
/* The entries at and below a node, in the dictionary's order. */
/* The entries at and below a node, the shortest keys first. */
static int
below(Trie *t, int ni, Str *out, int n, int max)
{