fast-trie-search
Advanced tools
+12
-12
@@ -10,4 +10,4 @@ "use strict"; | ||
| constructor() { | ||
| this.map = {}; | ||
| this.words = []; | ||
| this.m = {}; | ||
| this.w = []; | ||
| } | ||
@@ -48,3 +48,3 @@ } | ||
| if (opts.addKey === true) { | ||
| nodeObj.key = trieKey++; | ||
| nodeObj.k = trieKey++; | ||
| } | ||
@@ -62,3 +62,3 @@ if (!opts.excludeNodes.includes(expandedElement[i].toLowerCase())) { | ||
| // empty out the top level array as it serves no purpose and adds to the size | ||
| root.words = []; | ||
| root.w = []; | ||
| return root; | ||
@@ -70,10 +70,10 @@ }; | ||
| if (startIndex === node.length) { | ||
| root.words.push(str); | ||
| root.w.push(str); | ||
| return; | ||
| } | ||
| if (!root.map[node[startIndex]]) { | ||
| root.map[node[startIndex]] = new TrieNode(); | ||
| if (!root.m[node[startIndex]]) { | ||
| root.m[node[startIndex]] = new TrieNode(); | ||
| } | ||
| root.words.push(str); | ||
| add(str, startIndex + 1, root.map[node[startIndex]]); | ||
| root.w.push(str); | ||
| add(str, startIndex + 1, root.m[node[startIndex]]); | ||
| }; | ||
@@ -83,8 +83,8 @@ const search = (str, startIndex, root) => { | ||
| if (startIndex === str.length && startIndex !== 0) { | ||
| return root.words; | ||
| return root.w; | ||
| } | ||
| if (!root.map[str[startIndex]]) | ||
| if (!root.m[str[startIndex]]) | ||
| return []; | ||
| return search(str, startIndex + 1, root.map[str[startIndex]]); | ||
| return search(str, startIndex + 1, root.m[str[startIndex]]); | ||
| }; | ||
| exports.search = search; |
@@ -8,4 +8,4 @@ type Options = { | ||
| declare class TrieNode { | ||
| map: any; | ||
| words: any; | ||
| m: any; | ||
| w: any; | ||
| constructor(); | ||
@@ -12,0 +12,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"trieSearch.d.ts","sourceRoot":"","sources":["../../../src/trieSearch.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACX,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,cAAM,QAAQ;IACJ,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,GAAG,CAAC;;CAKrB;AAED,QAAA,MAAM,YAAY,aAAa,GAAG,cAAa,GAAG,YAAW,OAAO,aAuDnE,CAAA;AAkBD,QAAA,MAAM,MAAM,QAAS,MAAM,cAAc,MAAM,QAAQ,QAAQ,KAAE,GAUhE,CAAA;AAED,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAA"} | ||
| {"version":3,"file":"trieSearch.d.ts","sourceRoot":"","sources":["../../../src/trieSearch.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACX,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,cAAM,QAAQ;IACJ,CAAC,EAAE,GAAG,CAAC;IACP,CAAC,EAAE,GAAG,CAAC;;CAKjB;AAED,QAAA,MAAM,YAAY,aAAa,GAAG,cAAa,GAAG,YAAW,OAAO,aAuDnE,CAAA;AAkBD,QAAA,MAAM,MAAM,QAAS,MAAM,cAAc,MAAM,QAAQ,QAAQ,KAAE,GAUhE,CAAA;AAED,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAA"} |
+14
-14
| import parseRegex from "regex-parser"; | ||
| class TrieNode { | ||
| map; | ||
| words; | ||
| m; //map | ||
| w; //words | ||
| constructor() { | ||
| this.map = {}; | ||
| this.words = []; | ||
| this.m = {}; | ||
| this.w = []; | ||
| } | ||
@@ -42,3 +42,3 @@ } | ||
| if (opts.addKey === true) { | ||
| nodeObj.key = trieKey++; | ||
| nodeObj.k = trieKey++; | ||
| } | ||
@@ -56,3 +56,3 @@ if (!opts.excludeNodes.includes(expandedElement[i].toLowerCase())) { | ||
| // empty out the top level array as it serves no purpose and adds to the size | ||
| root.words = []; | ||
| root.w = []; | ||
| return root; | ||
@@ -63,10 +63,10 @@ }; | ||
| if (startIndex === node.length) { | ||
| root.words.push(str); | ||
| root.w.push(str); | ||
| return; | ||
| } | ||
| if (!root.map[node[startIndex]]) { | ||
| root.map[node[startIndex]] = new TrieNode(); | ||
| if (!root.m[node[startIndex]]) { | ||
| root.m[node[startIndex]] = new TrieNode(); | ||
| } | ||
| root.words.push(str); | ||
| add(str, startIndex + 1, root.map[node[startIndex]]); | ||
| root.w.push(str); | ||
| add(str, startIndex + 1, root.m[node[startIndex]]); | ||
| }; | ||
@@ -76,8 +76,8 @@ const search = (str, startIndex, root) => { | ||
| if (startIndex === str.length && startIndex !== 0) { | ||
| return root.words; | ||
| return root.w; | ||
| } | ||
| if (!root.map[str[startIndex]]) | ||
| if (!root.m[str[startIndex]]) | ||
| return []; | ||
| return search(str, startIndex + 1, root.map[str[startIndex]]); | ||
| return search(str, startIndex + 1, root.m[str[startIndex]]); | ||
| }; | ||
| export { generateTrie, search, TrieNode }; |
@@ -8,4 +8,4 @@ type Options = { | ||
| declare class TrieNode { | ||
| map: any; | ||
| words: any; | ||
| m: any; | ||
| w: any; | ||
| constructor(); | ||
@@ -12,0 +12,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"trieSearch.d.ts","sourceRoot":"","sources":["../../../src/trieSearch.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACX,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,cAAM,QAAQ;IACJ,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,GAAG,CAAC;;CAKrB;AAED,QAAA,MAAM,YAAY,aAAa,GAAG,cAAa,GAAG,YAAW,OAAO,aAuDnE,CAAA;AAkBD,QAAA,MAAM,MAAM,QAAS,MAAM,cAAc,MAAM,QAAQ,QAAQ,KAAE,GAUhE,CAAA;AAED,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAA"} | ||
| {"version":3,"file":"trieSearch.d.ts","sourceRoot":"","sources":["../../../src/trieSearch.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACX,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACzB,CAAA;AAED,cAAM,QAAQ;IACJ,CAAC,EAAE,GAAG,CAAC;IACP,CAAC,EAAE,GAAG,CAAC;;CAKjB;AAED,QAAA,MAAM,YAAY,aAAa,GAAG,cAAa,GAAG,YAAW,OAAO,aAuDnE,CAAA;AAkBD,QAAA,MAAM,MAAM,QAAS,MAAM,cAAc,MAAM,QAAQ,QAAQ,KAAE,GAUhE,CAAA;AAED,OAAO,EAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAC,CAAA"} |
+2
-2
| { | ||
| "name": "fast-trie-search", | ||
| "version": "1.1.4", | ||
| "description": "This package can be used to implement a Search-As-You-Type funtionality and uses a Trie data structure", | ||
| "version": "1.1.5", | ||
| "description": "This package can be used to implement a Search-As-You-Type funtionality and uses a Trie data structure ", | ||
| "exports": { | ||
@@ -6,0 +6,0 @@ ".": { |
18362
-0.38%