removed unwanted check for childCount and added childCount property in trie Node

This commit is contained in:
Dhroov Gupta
2019-08-09 23:21:00 +05:30
parent b7a5af4788
commit 4e94cf04d2
2 changed files with 4 additions and 8 deletions

View File

@@ -15,6 +15,9 @@ function Node (options) {
// stores all direct folder descendants of this node
this.children = {};
// number of folders in the sub-trie of this node
this.childCount = options ? options.childCount : 0;
this.requests = []; // request will always be an array of objects
this.addChildren = function (child, value) {

View File

@@ -330,16 +330,9 @@ module.exports = {
childCount: 0
}));
/* eslint-disable max-depth */
// We have to keep the count of folders under a current node as childCount
// For ex- In case of /pets/a/b, pets has 2 childCount (i.e a & b)
if (!currentNode.childCount) {
currentNode.childCount = 1;
}
else {
currentNode.childCount += 1;
}
/* eslint-enable */
currentNode.childCount += 1;
}
// requestCount increment for the node we just added
currentNode.children[currentPath[i]].requestCount += currentPathRequestCount;