Files
SnowLuma/.pnpm-store/v11/files/3a/3cad23f2c2f397501d8846f15f1fb7e961987dd98db52d4be787cbe3540fab796ddd9a6522b8cd67291d03ee6c102d8f62d25f2252f3e4c6c062a1fa1de295
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

42 lines
970 B
Plaintext

'use strict';
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);
}
}
module.exports = TrieNode;
//# sourceMappingURL=TrieNode.cjs.map