Skip to content

Commit

Permalink
feat(#232): 조상 노드 판별
Browse files Browse the repository at this point in the history
  • Loading branch information
Conut-1 committed Dec 13, 2023
1 parent c51c54c commit 51b2c30
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nestjs-BE/server/src/crdt/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export class Tree<T> {
return { nodes: Array.from(this.nodes.values()) };
}

isAncestor(targetId: string, ancestorId: string) {
let curNode = this.nodes.get(targetId);
while (curNode) {
if (curNode.parentId === ancestorId) return true;
curNode = this.nodes.get(curNode.parentId);
}
return false;
}

static parse<T>(json: string) {
const { nodes } = JSON.parse(json);
const tree = new Tree<T>();
Expand Down

0 comments on commit 51b2c30

Please sign in to comment.