forked from pyloque/fastscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
1 lines (1 loc) · 2.03 KB
/
index.min.js
1
!function(){"use strict";function t(t){this.root=function(t){t=function(t){t=(t=t.map(function(t){return t.trim()})).filter(function(t){return t.length>0});for(var n={},e=[],r=0;r<t.length;r++){var o=t[r];n[o]||(n[o]=!0,e[e.length]=o)}return e.sort()}(t);for(var e={next:{},val:null,back:null,parent:null,depth:0,accept:!1},r=0;r<t.length;r++)n(e,t[r]);return function(t){for(var n=Object.values(t.next);n.length>0;){for(var e=[],r=0;r<n.length;r++){var o=n[r];for(var a in o.next)e.push(o.next[a]);var u=o.parent,i=u.back;if(null!=i){var f=i.next[o.val];f&&(o.back=f)}}n=e}}(e),e}(t)}function n(t,n){for(var e=t,r=0;r<n.length;r++){var o=n[r];e.next[o]||(e.next[o]={next:{},val:o,accept:!1,back:t,parent:e,depth:e.depth+1}),e=e.next[o]}e.accept=!0}function e(t){for(var n=[];null!=t.val;)n.unshift(t.val),t=t.parent;return n.join("")}t.prototype.add=function(t){0!=(t=t.trim()).length&&(n(this.root,t),function(t,n){for(var e=t.next[n[0]],r=1;r<n.length;r++){var o=n[r],a=e.parent.back;if(null!=a){var u=a.next[e.val];u&&(e.back=u),e=e.next[o]}else e=e.next[o]}}(this.root,t))},t.prototype.locate=function(t){for(var n=this.root.next[t[0]],e=1;e<t.length;e++){var r=t[e];if(null==(n=n.next[r]))break}return n},t.prototype.hits=function(t,n){for(var e=this.search(t,n),r={},o=0;o<e.length;o++){var a=e[o][1],u=r[a]||0;r[a]=u+1}return r},t.prototype.search=function(t,n){var r=[],o=this.root;n=n||{};for(var a=0;a<t.length;){var u=t[a],i=o.next[u];if(i){if(o=i,a++,i.accept){var f=e(o);if(r.push([a-f.length,f]),n.quick)return r}}else{var l=o.back;if(null!=l){if(a-=o.depth-l.depth-1,(o=l).accept){f=e(o);if(r.push([a-f.length,f]),n.quick)return r}}else a++}}return n.longest?function(t){for(var n={},e=0;e<t.length;e++){var r=t[e],o=n[r[0]];(!o||o.length<r[1].length)&&(n[r[0]]=r[1])}return Object.keys(n).map(function(t){return parseInt(t)}).sort(function(t,n){return t-n}).map(function(t){return[t,n[t]]})}(r):r},"undefined"!=typeof module&&void 0!==module.exports?module.exports=t:"function"==typeof define&&define.amd?define([],function(){return t}):window.FastScanner=t}();