pascal lzh

, en meget hurtigt lzh kompressor, bidragyder: kurt haenen, {$r -} {ikke vifte kontrol.!} {, ---------------------------------------------------------------,      denne udstationering omfatter kilder til turbo pascal, version af lzrw1 /kh motorer algoritm., ---------------------------------------------------------------, fil: lzrw1kh enhed, --------------------------,} {###################################################################} {#&## #} {#&##&###### #####&##&##&##&##&##&##&##&##&##} {#&##&##&##&##&##&##&##&##&##&##&##&##&##&##&##} {#&##&##&## ##### #######&##&##&##&## ######&##} {#&##&##&##&##&##&##&##&##&##&###&##&##&##&## #} {#&###### #####&##&##&##&##&##&##&##&##&##&##&##&##} {#&## #} {#&#meget hurtigt og let at forstå motorer algoritm&##} (#&## #} {###################################################################} {#&## #} {#&#denne enhed gennemfører den ajourførte lzrw1 /kh algoritm, som&##} {#&#også gennemfører nogle rle kodning, der er nyttig, når&##} {#&#komprimere filer, der indeholder mange på hinanden følgende bytes&##} {#&#under.den samme værdi.den algoritm ikke er så god, som&##} {#&#lzh, men kan konkurrere med lempel. ziff.det ' er fastende&##} {#&#jeg ' har oplevet indtil nu.# #} {#&## #} {#&## #} {#&## #} {#&#kurt haenen&##} {#&## #} {###################################################################}, enhed lzrw1kh; interface, bruger sysutils; ($ifdef win32}, type int16 = smallint; ($andet}, type int16 = heltal ($endif}, konstant,      buffermaxsize = 32768;,      buffermax = buffermaxsize-1;,      flag_copied = 80 dollars.      flag_compress = 40 dollars.type,      bufferindex = 0. buffermax + 15,      buffersize = 0. buffermaxsize;,         (ekstra byte nødvendig her, hvis motorer ikke *) *),      bufferarray = system [bufferindex] byte;,      bufferptr = ^ bufferarray;,      elzrw1khcompressor = klasse (undtagelse), funktion motorer (kilde: bufferptr;, -                                sourcesize: buffersize): buffersize;, funktion dekompression (kilde: bufferptr;, -                                sourcesize: buffersize): buffersize;, gennemførelse, type,    hashtable = system [0 - 4095] af int16;,    hashtabptr = ^hashtable;, var,    hash: hashtabptr;,                               {se, om den her allerede har set},                               {i det nuværende 4 kb vindue}, funktion getmatch (kilde: bufferptr;,                                x: bufferindex;,                                sourcesize: buffersize;,                                hash: hashtabptr,                            var størrelse: ord; og,                            var bufferi producentorganisationer:ndex ) : BOOLEAN;, VAR,   HashValue : WORD;,   TmpHash : Int16;, BEGIN,   HashValue := (40543*((((Source^[X] SHL 4) XOR Source^[X+1]) SHL 4) XOR,                                      Source^[X+2]) SHR 4) AND $0FFF;,   Result := FALSE;,   TmpHash := Hash^[HashValue];,   IF (TmpHash <> -1) and (X - TmpHash < 4096) THEN BEGIN,     Pos := TmpHash;,     Size := 0;,     WHILE ((Size < 18) AND (Source^[X+Size] = Source^[Pos+Size]),                        AND (X+Size < SourceSize)) DO begin,       INC(Size);,     end;,     Result := (Size >= 3),   END;,   Hash^[HashValue] := X, END; ,,                                      {kompres en buffer på højst 32 b}, funktion motorer (kilde: bufferptr;, -                        sourcesize: buffersize): buffersize;, var,    lidt, kommando, størrelse: ord;,    nøgle: ord;,    x, y og z, producentorganisationer: bufferindex;, begynder,    fillchar ('), 7 (hashtable), $ff),    - ([0]: = flag_compress;,    x: = 0,    y: = 3,    z: = 1,    del: = 0,    kommando: = 0,   , mens (x < sourcesize) og y < = sourcesize) begynder,      hvis (bed > 15) så begynde,        best ^ [z]: = hej (kommando),        best ^ [z + 1] = lo (kommando),        z: = y;,        lidt:= 0;,       INC(Y,2),     END;,     Size := 1;,     WHILE ((Source^[X] = Source^[X+Size]) AND (Size < $FFF),                          AND (X+Size < SourceSize)) DO begin,               INC(Size);,     end;,     IF (Size >= 16) THEN BEGIN,       Dest^[Y] := 0;,       Dest^[Y+1] := HI(Size-16);,       Dest^[Y+2] := LO(Size-16);,       Dest^[Y+3] := Source^[X];,       INC(Y,4);,       INC(X,Size);,       Command := (Command SHL 1) + 1;,     END,     ELSE begin { not size >= 16 },       IF (GetMatch(Source,X,SourceSize,Hash,Size,Pos)) THEN BEGIN,         Key := ((X-Pos) SHL 4) + (Size-3);,          best ^ [x]: = hej (centrale),          best ^ [x + 1] = lo (centrale),          inc (y, 2),          inc (x, størrelse),          kommando: = (kommando sømhaj shb. 1 + 1,       ,        ellers begynder,          best ^ [x]: = kilde ^ [x];,          inc (y),          inc. (x),          kommando: = kommando sømhaj shb 1,       ;,      størrelse; (< = 16),      inc (bit),   ; (mens x < sourcesize...},    kommando: = kommando sømhaj shb (16 - bit),    best ^ [z]: = hej (kommando),    best ^ [z + 1] = lo (kommando),    hvis (y > sourcesize) så begynde,      træk (kilde ([0], dest) [1], sourcesize),      - ([0]: = flag_copied;,      y: = succ (sourcesize),   ;,    resultat: = y,;,                                      {dekompresse en buffer på max 32 b}, funktion dekompression (kilde: bufferptr -;,                          sourcesize: buffersize): buffersize;, var,    x, y, producentorganisationer: bufferindex;,    kommando, størrelse, k: ord;,    del: byte;,    savey: bufferindex. {*) * usikker for loop variable y}, BEGIN,   IF (Source^[0] = FLAG_Copied) THEN begin,     FOR Y := 1 TO PRED(SourceSize) DO begin,       Dest^[PRED(Y)] := Source^[Y];,       SaveY := Y;,     end;,     Y := SaveY;,   end,   ELSE BEGIN,     Y := 0;,     X := 3;,     Command := (Source^[1] SHL 8) + Source^[2];,     Bit := 16;,     WHILE (X < SourceSize) DO BEGIN,       IF (Bit = 0) THEN BEGIN,         Command := (Source^[X] SHL 8) + Source^[X+1];,         Bit := 16;,         INC(X,2),       END;,       IF ((Command AND $8000) = 0) THEN BEGIN,            Dest^[Y] := Source^[X];,            INC(X);,            INC(Y),       END,       ELSE BEGIN { command and $8000 },         Pos := ((Source^[X] SHL 4),                +(Source^[X+1] SHR 4));,         IF (Pos = 0) THEN BEGIN,           Size := (Source^[X+1] SHL 8) + Source^[X+2] + 15;,           FOR K := 0 TO Size DO begin,                Dest^[Y+K] := Source^[X+3];,           end;,           INC(X,4);,           INC(Y,Size+1),         END,         ELSE BEGIN { pos = 0 },           Size := (Source^[X+1] AND $0F)+2;,           FOR K := 0 TO Size DO,                Dest^[Y+K] := Dest^[Y-Pos+K];,           INC(X,2);,           INC(Y,Size+1),         END; { pos = 0 },       END; { command and $8000 },       Command := Command SHL 1;,       DEC(Bit),     END { while x < sourcesize },   END;,   Result := Y, END; { decompression }, {,   Unit "Finalization" as Delphi 2.0 would have it, }, var,   ExitSave : Pointer;, Procedure Cleanup; far;, begin,   ExitProc := ExitSave;,   if (Hash <> Nil) then,     Freemem(Hash, Sizeof(HashTable));, end;, Initialization,   Hash := Nil;,   try,     Getmem(Hash,Sizeof(Hashtable));,   except,     Raise ELzrw1KHCompressor.Create('LZRW1KH : no memory for HASH table');,   end;,   ExitSave := ExitProc;,   ExitProc := @Cleanup;, END.,



Previous:
Next Page: