Files
SnowLuma/.pnpm-store/v11/files/96/9c5f895d71a2e565b2de41d2e34d2ca8b1dd04b335ecab6cae5fd51c05744d4e39da94e08c1323247ac4d54a8086ff73d96e3c5dde0e817387773c687ed067
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

40 lines
960 B
Plaintext

class TrieNode {
constructor(parents = []) {
this.parents = parents;
this.children = new Map();
}
addSub(key, ...subs) {
const firstChar = key.charAt(0);
if (!this.children.has(firstChar)) {
this.children.set(firstChar, new TrieNode([...this.parents, firstChar]));
}
let cur = this.children.get(firstChar);
for (let i = 1; i < key.length; i += 1) {
const c = key.charAt(i);
if (!cur.hasChild(c)) {
cur.addChild(c);
}
cur = cur.getChild(c);
}
cur.subs = (cur.subs || []).concat(subs);
return this;
}
getChild(child) {
return this.children.get(child);
}
isTerminal() {
return !!this.subs;
}
addChild(child) {
if (!this.hasChild(child)) {
this.children.set(child, new TrieNode([...this.parents, child]));
}
}
hasChild(child) {
return this.children.has(child);
}
}
export { TrieNode as default };
//# sourceMappingURL=TrieNode.mjs.map