2
constructor(val, parent) {3
(this.val = val), (this.parent = parent), (this.children = {}), this.hash;8
this.root = new Node("");13
for (let node of path)14
if (cur.children[node] !== undefined) cur = cur.children[node];16
(cur.children[node] = new Node(node, cur)), (cur = cur.children[node]);18
traverse(node = this.root) {21
for (let child of Object.values(node.children))22
node.hash.push(this.traverse(child));23
node.hash = node.hash.join("~");24
if (node.hash !== "") {25
if (this.hashMemo[node.hash] === undefined) this.hashMemo[node.hash] = [];26
this.hashMemo[node.hash].push(node);27
return node.val + "/[" + node.hash + "]";31
delete(node = this.root) {32
if (!node || node.hash === undefined) return;33
else if (this.hashMemo[node.hash] && this.hashMemo[node.hash].length > 1)34
for (let todelete of this.hashMemo[node.hash])35
delete todelete.parent.children[todelete.val];36
else for (let child of Object.values(node.children)) this.delete(child);38
serialize(node = this.root, stack = [], res = []) {39
if (node.val !== "") stack.push(node.val), res.push([...stack]);40
for (let child of Object.values(node.children))41
this.serialize(child, stack, res);47
var deleteDuplicateFolder = function (paths) {49
for (let P of paths) T.insert(P);