Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lz77_compress(str, dictlen, bufflen){
- let dl=dictlen, drl=0, bl=bufflen;
- let maxlen, maxa, maxk, output=[];
- while( str.length>drl ){
- maxlen=0;
- maxk=0;
- for(let i=Math.max(drl-dl,0); i<drl; i++){
- let l=i, k=0;
- while( drl+k<str.length-1 && k+1<bl && str[l]==str[drl+k] ){
- l++;
- k++;
- }
- if( l-i>maxlen ){
- maxlen=l-i;
- maxa=i;
- maxk=k;
- }
- }
- if( maxlen!=0 ){
- let ind = maxa-(drl-dl);
- output.push( {
- index: ind, length: maxlen, char: str[drl+maxk]
- } );
- }else{
- output.push( {
- index: 0, length: 0, char: str[drl+maxk]
- } );
- }
- drl += maxlen+1;
- }
- return output;
- }
Add Comment
Please, Sign In to add comment