export class FilePathScoreFunction{constructor(e){this._query=e,this._queryUpperCase=e.toUpperCase(),this._score=new Int32Array(2e3),this._sequence=new Int32Array(2e3),this._dataUpperCase="",this._fileNameIndex=0}score(e,t){if(!e||!this._query)return 0;const r=this._query.length,s=e.length;(!this._score||this._score.length<r*s)&&(this._score=new Int32Array(r*s*2),this._sequence=new Int32Array(r*s*2));const a=this._score,h=this._sequence;this._dataUpperCase=e.toUpperCase(),this._fileNameIndex=e.lastIndexOf("/");for(let i=0;i<r;++i)for(let t=0;t<s;++t){const r=0===t?0:a[i*s+t-1],n=0===i||0===t?0:a[(i-1)*s+t-1],_=0===i||0===t?0:h[(i-1)*s+t-1],c=this._match(this._query,e,i,t,_);c&&n+c>=r?(h[i*s+t]=_+1,a[i*s+t]=n+c):(h[i*s+t]=0,a[i*s+t]=r)}t&&this._restoreMatchIndexes(h,r,s,t);return 256*a[r*s-1]+(256-e.length)}_testWordStart(e,t){if(0===t)return!0;const r=e.charAt(t-1);return"_"===r||"-"===r||"/"===r||"."===r||" "===r||e[t-1]!==this._dataUpperCase[t-1]&&e[t]===this._dataUpperCase[t]}_restoreMatchIndexes(e,t,r,s){let a=t-1,h=r-1;for(;a>=0&&h>=0;)switch(e[a*r+h]){case 0:--h;break;default:s.push(h),--a,--h}s.reverse()}_singleCharScore(e,t,r,s){const a=this._testWordStart(t,s),h=s>this._fileNameIndex;let i=10;return(0===s||"/"===t[s-1])&&(i+=4),a&&(i+=2),e[r]===t[s]&&e[r]===this._queryUpperCase[r]&&(i+=6),h&&(i+=4),s===this._fileNameIndex+1&&0===r&&(i+=5),h&&a&&(i+=3),i}_sequenceCharScore(e,t,r,s,a){let h=10;return s>this._fileNameIndex&&(h+=4),(0===s||"/"===t[s-1])&&(h+=5),h+=4*a,h}_match(e,t,r,s,a){return this._queryUpperCase[r]!==this._dataUpperCase[s]?0:a?this._sequenceCharScore(e,t,r,s-a,a):this._singleCharScore(e,t,r,s)}}