prefix-trie-ts
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,4 @@ | ||
#[0.0.2] 4-17-2017 | ||
- Restored `getWords` method. | ||
#[0.0.1] 4-11-2017 | ||
@@ -2,0 +5,0 @@ - Cloned from https://github.com/lyndseybrowning/trie-prefix-tree |
@@ -1,1 +0,1 @@ | ||
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var t={};return r.m=e,r.c=t,r.i=function(e){return e},r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.e?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},r.p="",r(r.s=1)}([function(e,r){Object.defineProperty(r,"__esModule",{value:!0});var t={END_WORD:"$",PERMS_MIN_LEN:2},n=function(){function e(r){this.r=e.t(r)}return e.prototype.addWord=function(r){var t=function(r,t,n,o){return e.u(r,t,n,o)};return r.toLowerCase().split("").reduce(t,this.r),this},e.prototype.removeWord=function(r){var n=e.f(this.r,r),o=n.prefixFound,i=n.prefixNode;return o&&delete i[t.END_WORD],this},e.prototype.a=function(r){return e.f(this.r,r).prefixFound},e.prototype.getPrefix=function(r){if(r=r.toLowerCase(),!this.a(r))return[];var t=e.f(this.r,r).prefixNode;return e._(t,r)},e.u=function(e,r,n,o){return e[r]=e[r]||{},e=e[r],n===o.length-1&&(e[t.END_WORD]=1),e},e.f=function(e,r){return{prefixFound:r.toLowerCase().split("").every(function(r,t){return!!e[r]&&(e=e[r])}),prefixNode:e}},e.t=function(r){return r.reduce(function(r,t){return t.toLowerCase().split("").reduce(e.u,r),r},{})},e._=function(r,n,o){void 0===o&&(o=[]);var i=n;for(var u in r)u===t.END_WORD&&(o.push(i),i=""),e._(r[u],n+u,o);return o.sort()},e}();r.Trie=n},function(e,r,t){e.exports=t(0)}])}); | ||
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,function(){return function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var t={};return r.m=e,r.c=t,r.i=function(e){return e},r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.e?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},r.p="",r(r.s=1)}([function(e,r){Object.defineProperty(r,"__esModule",{value:!0});var t={END_WORD:"$",PERMS_MIN_LEN:2},n=function(){function e(r){this.r=e.t(r)}return e.prototype.addWord=function(r){var t=function(r,t,n,o){return e.u(r,t,n,o)};return r.toLowerCase().split("").reduce(t,this.r),this},e.prototype.removeWord=function(r){var n=e.f(this.r,r),o=n.prefixFound,i=n.prefixNode;return o&&delete i[t.END_WORD],this},e.prototype.getWords=function(){return e._(this.r,"")},e.prototype.getPrefix=function(r){if(r=r.toLowerCase(),!this.a(r))return[];var t=e.f(this.r,r).prefixNode;return e._(t,r)},e.prototype.a=function(r){return e.f(this.r,r).prefixFound},e.u=function(e,r,n,o){return e[r]=e[r]||{},e=e[r],n===o.length-1&&(e[t.END_WORD]=1),e},e.f=function(e,r){return{prefixFound:r.toLowerCase().split("").every(function(r,t){return!!e[r]&&(e=e[r])}),prefixNode:e}},e.t=function(r){return r.reduce(function(r,t){return t.toLowerCase().split("").reduce(e.u,r),r},{})},e._=function(r,n,o){void 0===o&&(o=[]);var i=n;for(var u in r)u===t.END_WORD&&(o.push(i),i=""),e._(r[u],n+u,o);return o.sort()},e}();r.Trie=n},function(e,r,t){e.exports=t(0)}])}); |
export declare class Trie { | ||
constructor(input: string[]); | ||
constructor(input?: string[]); | ||
addWord(word: string): this; | ||
removeWord(word: string): this; | ||
getWords(): string[]; | ||
getPrefix(strPrefix: string): string[]; | ||
} |
@@ -25,5 +25,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}; | ||
Trie.prototype._isPrefix = function (prefix) { | ||
var prefixFound = Trie._checkPrefix(this._trie, prefix).prefixFound; | ||
return prefixFound; | ||
Trie.prototype.getWords = function () { | ||
return Trie._recursePrefix(this._trie, ''); | ||
}; | ||
@@ -38,2 +37,6 @@ Trie.prototype.getPrefix = function (strPrefix) { | ||
}; | ||
Trie.prototype._isPrefix = function (prefix) { | ||
var prefixFound = Trie._checkPrefix(this._trie, prefix).prefixFound; | ||
return prefixFound; | ||
}; | ||
Trie._append = function (trie, letter, index, array) { | ||
@@ -40,0 +43,0 @@ trie[letter] = trie[letter] || {}; |
{ | ||
"name": "prefix-trie-ts", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Create and modify trie prefix structures, extract word lists including anagrams and sub-anagrams", | ||
@@ -5,0 +5,0 @@ "main": "node/index.js", |
@@ -56,2 +56,8 @@ # Prefix Trie TS | ||
### Get All Words | ||
List all words in the word list. | ||
```js | ||
trie.getWords() | ||
``` | ||
### Get Prefix | ||
@@ -58,0 +64,0 @@ Search the trie for all words that begin with or match a given string. Returns an array of found strings. |
@@ -17,3 +17,3 @@ const config = { | ||
constructor(input: string[]) { | ||
constructor(input?: string[]) { | ||
this._trie = Trie._create(input); | ||
@@ -44,2 +44,17 @@ } | ||
public getWords() { | ||
return Trie._recursePrefix(this._trie, ''); | ||
} | ||
public getPrefix(strPrefix: string) { | ||
strPrefix = strPrefix.toLowerCase(); | ||
if (!this._isPrefix(strPrefix)) { | ||
return []; | ||
} | ||
const { prefixNode } = Trie._checkPrefix(this._trie, strPrefix); | ||
return Trie._recursePrefix(prefixNode, strPrefix); | ||
} | ||
/** | ||
@@ -61,13 +76,2 @@ * | ||
public getPrefix(strPrefix: string) { | ||
strPrefix = strPrefix.toLowerCase(); | ||
if (!this._isPrefix(strPrefix)) { | ||
return []; | ||
} | ||
const { prefixNode } = Trie._checkPrefix(this._trie, strPrefix); | ||
return Trie._recursePrefix(prefixNode, strPrefix); | ||
} | ||
/** | ||
@@ -74,0 +78,0 @@ * |
67
27770
11
293