1 | export const NODE_TYPE_ROOT = Symbol("ROOT");
|
2 | export const NODE_TYPE_CHILD = Symbol("CHILD");
|
3 | export const createRootNode = () => {
|
4 | return {
|
5 | type: NODE_TYPE_ROOT,
|
6 | children: new Map(),
|
7 | };
|
8 | };
|
9 | export const createOrGetChild = (parent, label) => {
|
10 | let child = parent.children.get(label);
|
11 | if (child === undefined) {
|
12 | child = {
|
13 | type: NODE_TYPE_CHILD,
|
14 | label,
|
15 | children: new Map(),
|
16 | parent,
|
17 | };
|
18 | parent.children.set(label, child);
|
19 | }
|
20 | return child;
|
21 | };
|
22 |
|
\ | No newline at end of file |