Refactoring, comments, moving trie lib to a separate file

This commit is contained in:
abhijitkane
2018-12-10 21:51:03 +05:30
parent 9e5a27643f
commit 21f1fb53ab
2 changed files with 174 additions and 127 deletions

38
lib/trie.js Normal file
View File

@@ -0,0 +1,38 @@
/**
* Class for the node of the tree containing the folders
* @param {object} options - Contains details about the folder/collection node
* @returns {void}
*/
function Node (options) {
// human-readable name
this.name = options ? options.name : '/';
// number of requests in the sub-trie of this node
this.requestCount = options ? options.requestCount : 0;
this.type = options ? options.type : 'item';
// stores all direct folder descendants of this node
this.children = {};
this.requests = options ? options.requests : []; // request will be an array of objects
this.addChildren = function (child, value) {
this.children[child] = value;
};
this.addMethod = function (method) {
this.requests.push(method);
};
}
class Trie {
constructor(node) {
this.root = node;
}
}
module.exports = {
Trie: Trie,
Node: Node
};