emoji: search the dictionary by prefix in the engine, not in the data

mkemoji wrote a row for every prefix of every alias, so that a query
matched as it was typed; the trie is a prefix index already, and with a
real emoji list those rows would be four times the aliases themselves.
Now emoji.dict has one row per alias, trienode() names a key's node, and
dictlookup walks the entries at and below it, the key's own first, up to
Maxkouho.  Trie children are appended rather than pushed, so the walk
keeps the file's order and a bare digit still picks the superscript or
subscript it always did.

The hand-written symbol rows move to symbol.src; emoji.src is left to
the emoji.  mkemoji reads both by default, or the files it is given.
This commit is contained in:
2026-08-17 01:07:10 +09:00
parent 221117f93d
commit abff5ed122
9 changed files with 275 additions and 386 deletions

38
trie.c
View File

@@ -35,15 +35,21 @@ find(Trie *t, int ni, char c)
return -1;
}
/* Appends, so that a walk of the children keeps the file's order. */
static int
add(Trie *t, int ni, char c)
{
int pi;
int last, pi;
last = -1;
for(pi = t->nodes[ni].child; pi >= 0; pi = t->nodes[pi].sibling)
last = pi;
pi = newnode(t);
t->nodes[pi].c = c;
t->nodes[pi].sibling = t->nodes[ni].child;
t->nodes[ni].child = pi;
if(last < 0)
t->nodes[ni].child = pi;
else
t->nodes[last].sibling = pi;
return pi;
}
@@ -153,24 +159,32 @@ trieclose(Trie *t)
free(t);
}
/* A nil trie is an unloaded map: every key misses. */
/* The node key leads to, or -1. A nil trie is an unloaded map: every key misses. */
int
trielookup(Trie *t, Str *key, char **val, int *vlen)
trienode(Trie *t, Str *key)
{
char buf[Maxutf];
int i, klen, ni;
*val = nil;
*vlen = 0;
if(t == nil)
return TrieMiss;
return -1;
klen = stoutf(key, buf, sizeof buf);
ni = 0;
for(i = 0; i < klen; i++){
for(i = 0; i < klen && ni >= 0; i++)
ni = find(t, ni, buf[i]);
if(ni < 0)
return TrieMiss;
}
return ni;
}
int
trielookup(Trie *t, Str *key, char **val, int *vlen)
{
int ni;
*val = nil;
*vlen = 0;
ni = trienode(t, key);
if(ni < 0)
return TrieMiss;
if(t->nodes[ni].val == nil)
return TriePrefix;
*val = t->nodes[ni].val;