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 51b2c30 commit 8b47b87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nestjs-BE/server/src/crdt/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export class OperationMove<T> extends Operation<T> {
const node = tree.get(this.id);
const oldParentId = node.parentId;

if (tree.isAncestor(this.parentId, this.id)) {
return { operation: this, oldParentId };
}

tree.removeNode(this.id);
tree.attachNode(this.id, this.parentId);
return { operation: this, oldParentId };
Expand Down
1 change: 1 addition & 0 deletions nestjs-BE/server/src/crdt/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class Tree<T> {

const targetIndex = parentNode.children.indexOf(targetId);
if (targetIndex !== -1) parentNode.children.splice(targetIndex, 1);
targetNode.parentId = '0';

return this.nodes.get(targetId);
}
Expand Down

0 comments on commit 8b47b87

Please sign in to comment.