数据压缩 -- 源码[12]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 luckyjan 的 blog

  getmem(text,2*dicsiz+maxmatch);
  getmem(level,dicsiz+ucharmax+1);
  getmem(childcount,dicsiz+ucharmax+1);
{$ifdef percolate}
  getmem(position,(dicsiz+ucharmax+1)*sizeof(word));
{$else}
  getmem(position,(dicsiz)*sizeof(word));
{$endif}
  getmem(parent,(dicsiz*2)*sizeof(word));
  getmem(prev,(dicsiz*2)*sizeof(word));
  getmem(next,(maxhashval+1)*sizeof(word));

  depth:=0;
  initslide;
  getmem(buf,windowsize);
  buf^[0]:=0;
  fillchar(cfreq,sizeof(cfreq),0);
  fillchar(pfreq,sizeof(pfreq),0);
  outputpos:=0;outputmask:=0;initputbits;
  remainder:=infile.read(text^[dicsiz],dicsiz+maxmatch);
  matchlen:=0;pos:=dicsiz;insertnode;
  if matchlen>remainder then
    matchlen:=remainder;
  while remainder>0 do begin
    lastmatchlen:=matchlen;lastmatchpos:=matchpos;getnextmatch;
    if matchlen>remainder then
      matchlen:=remainder;
    if (matchlen>lastmatchlen)or(lastmatchlen<threshold) then
      output(text^[pred(pos)],0)
    else
      begin
        output(lastmatchlen+(ucharmax+1-threshold),(pos-lastmatchpos-2)and pred(dicsiz));
        dec(lastmatchlen);
        while lastmatchlen>0 do begin
          getnextmatch;dec(lastmatchlen);
        end;
        if matchlen>remainder then
          matchlen:=remainder;
      end;
  end;
  {flush buffers}
  sendblock;putbits(7,0);
  if bufptr<>0 then
    outfile.write(buffer^,bufptr);

  freemem(buf,windowsize);
  freemem(next,(maxhashval+1)*sizeof(word));
  freemem(prev,(dicsiz*2)*sizeof(word));
  freemem(parent,(dicsiz*2)*sizeof(word));
{$ifdef percolate}
  freemem(position,(dicsiz+ucharmax+1)*sizeof(word));
{$else}
  freemem(position,(dicsiz)*sizeof(word));
{$endif}
  freemem(childcount,dicsiz+ucharmax+1);
  freemem(level,dicsiz+ucharmax+1);
  freemem(text,2*dicsiz+maxmatch);
end;

{****************************** lh5 as unit procedures ************************}
procedure freememory;
begin
  if clen <> nil    then dispose(clen);    clen := nil;
  if ctable <> nil  then dispose(ctable);  ctable := nil;
  if right <> nil   then dispose(right);   right := nil;
  if left <> nil    then dispose(left);    left := nil;
  if buffer <> nil  then dispose(buffer);  buffer := nil;
  if heap <> nil    then dispose(heap);    heap := nil;
end;

procedure initmemory;
begin
  {in should be harmless to call freememory here, since it won't free
   unallocated memory (i.e., nil pointers).
   so let's call it in case an exception was thrown at some point and
   memory wasn't entirely freed.}
  freememory;
  new(buffer);
  new(left);
  new(right);
  new(ctable);
  new(clen);
  fillchar(buffer^,sizeof(buffer^),0);
  fillchar(left^,sizeof(left^),0);
  fillchar(right^,sizeof(right^),0);
  fillchar(ctable^,sizeof(ctable^),0);
  fillchar(clen^,sizeof(clen^),0);

  decode_i := 0;
  bitbuf := 0;
  n := 0;
  heapsize := 0;
  subbitbuf := 0;
  bitcount := 0;
  bufptr := 0;
  fillchar(pttable, sizeof(pttable),0);
  fillchar(ptlen, sizeof(ptlen),0);
  blocksize := 0;

  { the following variables are used by the compression engine only }
  new(heap);
  fillchar(heap^, sizeof(heap^),0);
  fillchar(lencnt, sizeof(lencnt),0);
  depth := 0;
  fillchar(cfreq, sizeof(cfreq),0);
  fillchar(pfreq, sizeof(pfreq),0);
  fillchar(tfreq, sizeof(tfreq),0);
  fillchar(ccode, sizeof(ccode),0);
  fillchar(ptcode, sizeof(ptcode),0);
  cpos := 0;
  outputpos := 0;
  outputmask := 0;
  pos := 0;
  matchpos := 0;
  avail := 0;
  remainder := 0;

本文关键:数据压缩 -- 源码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top