请问谁有简单的字符串压缩程序 ( 积分: 200 )

  • 主题发起人 主题发起人 zwd2000
  • 开始时间 开始时间
Z

zwd2000

Unregistered / Unconfirmed
GUEST, unregistred user!
请问谁有简单的字符串压缩程序
 
请问谁有简单的字符串压缩程序
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1798618
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2136144
 
谁有能将长字符压缩成短字符的算法! (100分)
分类:系统相关 zyq.ks (2003-06-03 10:49:00)
要求:压缩后的字符为可见字符,压缩率不要求太高!有解压算法!

rockjie (2003-06-03 10:50:00)
网上好像有过资料,现在只能帮你顶了

helloqiner (2003-06-03 11:10:00)
李维的Delphi 6/ Kylix2 Soap/Web Service第12章中有示例,但我按他的方法去做发现算法很不稳定,关注.


zyq.ks (2003-06-03 11:43:00)
up...................................

天真男孩 (2003-06-03 12:58:00)
up.................



chenxz (2003-06-03 14:29:00)
不是很明白你的意思,用bcd码压可以吗

zyq.ks (2003-06-05 11:38:00)
bcd码压缩率也太低了!

ftop1 (2003-06-05 11:44:00)
AAA

helloqiner (2003-06-05 12:12:00)
我想自己定算法很累的,不如调用现有的控件,如Zip、rar等,将字符串压缩成流,然后用Base64对流进行编码,生成可见字符的字串。


likongxu (2003-06-05 12:32:00)
字符串压缩算法

Contributor: SWAG SUPPORT TEAM

{You won't get that sort of compression from my routines, but here

they are anyway. When testing, you'll get best compression if you

use English and longish Strings.

}

Unit Compress;

Interface

Const

CompressedStringArraySize = 500;
{ err on the side of generosity }

Type

tCompressedStringArray = Array[1..CompressedStringArraySize] of Byte;

Function GetCompressedString(Arr : tCompressedStringArray) : String;

Procedure CompressString(st : String;
Var Arr : tCompressedStringArray;

Var len : Integer);

{ converts st into a tCompressedStringArray of length len }

Implementation

Const

FreqChar : Array[4..14] of Char = 'etaonirshdl';

{ can't be in [0..3] because two empty bits signify a space }

 

Function GetCompressedString(Arr : tCompressedStringArray) : String;

Var

Shift : Byte;

I : Integer;

ch : Char;

st : String;

b : Byte;

Function GetHalfNibble : Byte;

begin


GetHalfNibble := (Arr shr Shift) and 3;

if Shift = 0 then
begin


Shift := 6;

inc(I);

end else
dec(Shift,2);

end;


begin


st := '';

I := 1;

Shift := 6;

Repeat

b := GetHalfNibble;

if b = 0 then


ch := ' '

else
begin


b := (b shl 2) or GetHalfNibble;

if b = $F then
begin


b := GetHalfNibble shl 6;

b := b or GetHalfNibble shl 4;

b := b or GetHalfNibble shl 2;

b := b or GetHalfNibble;

ch := Char(b);

end else


ch := FreqChar;

end;


if ch <>
#0 then
st := st + ch;

Until ch = #0;

GetCompressedString := st;

end;


Procedure CompressString(st : String;
Var Arr : tCompressedStringArray;

Var len : Integer);

{ converts st into a tCompressedStringArray of length len }

Var

I : Integer;

Shift : Byte;

Procedure OutHalfNibble(b : Byte);

begin


Arr[len] := Arr[len] or (b shl Shift);

if Shift = 0 then
begin


Shift := 6;

inc(len);

end else
dec(Shift,2);

end;


Procedure OutChar(ch : Char);

Var

I : Byte;

bych : Byte Absolute ch;

begin


if ch = ' ' then


OutHalfNibble(0)

else
begin


I := 4;

While (I<15) and (FreqChar<>ch)do
inc(I);

OutHalfNibble(I shr 2);

OutHalfNibble(I and 3);

if I = $F then
begin


OutHalfNibble(bych shr 6);

OutHalfNibble((bych shr 4) and 3);

OutHalfNibble((bych shr 2) and 3);

OutHalfNibble(bych and 3);

end;


end;


end;


begin


len := 1;

Shift := 6;

fillChar(Arr,sizeof(Arr),0);

For I := 1 to length(st)do
OutChar(st);

OutChar(#0);
{ end of compressed String signaled by #0 }

if Shift = 6

then
dec(len);

end;


end.


测试压缩字符串

Contributor: SWAG SUPPORT TEAM

Program TestComp;
{ tests Compression }

{ kludgy test of Compress Unit }

Uses Crt,do
s, Compress;

Const

NumofStrings = 5;

Var

ch : Char;

LongestStringLength,I,j,len : Integer;

Textfname,Compfname : String;

TextFile : Text;

ByteFile : File;

CompArr : tCompressedStringArray;

st : Array[1..NumofStrings] of String;

Rec : SearchRec;

BigArr : Array[1..5000] of Byte;

Arr : Array[1..NumofStrings] of tCompressedStringArray;

begin


Writeln('note: No I/O checking in this test.');

Write('Test ompress or nCompress? ');

Repeat

ch := upCase(ReadKey);

Until ch in ['C','U',#27];

if ch = #27 then
halt;

Writeln(ch);

if ch = 'C' then
begin


Writeln('Enter ',NumofStrings,' Strings:');

LongestStringLength := 0;

For I := 1 to NumofStringsdo
begin


Write(I,': ');

readln(st);

if length(st) >
LongestStringLength then


LongestStringLength := length(st);

end;


Writeln;

Writeln('Enter name of File to store unCompressed Strings in.');

Writeln('ANY EXISTinG File With THIS NAME WILL BE OVERWRITTEN.');

readln(Textfname);

assign(TextFile,Textfname);

reWrite(TextFile);

For I := 1 to NumofStringsdo


Writeln(TextFile,st);

close(TextFile);

Writeln;

Writeln('Enter name of File to store Compressed Strings in.');

Writeln('ANY EXISTinG File With THIS NAME WILL BE OVERWRITTEN.');

readln(Compfname);

assign(ByteFile,Compfname);

reWrite(ByteFile,1);

For I := 1 to NumofStringsdo
begin


CompressString(st,CompArr,len);

blockWrite(ByteFile,CompArr,len);

end;


close(ByteFile);

FindFirst(Textfname,AnyFile,Rec);

Writeln;

Writeln;

Writeln('Size of Text File storing Strings: ',Rec.Size);

Writeln;

Writeln('Using Typed Files, a File of Type String[',

LongestStringLength,

'] would be necessary.');

Writeln('That would be ',

(LongestStringLength+1)*NumofStrings,

' long, including length Bytes.');

Writeln;

FindFirst(Compfname,AnyFile,Rec);

Writeln('Size of the Compressed File: ',Rec.Size);

Writeln;

Writeln('Now erase the Text File, and run this Program again, choosing');

Writeln('nCompress to show that the Compression retains all info.');

end else
begin
{ ch = 'U' }

Write('Name of Compressed File: ');

readln(Compfname);

assign(ByteFile,Compfname);

reset(ByteFile,1);

blockread(ByteFile,BigArr,Filesize(ByteFile));

close(ByteFile);

For j := 1 to NumofStringsdo
begin


I := 1;

While BigArr <>
0do
inc(I);

move(BigArr[1],Arr[j],I);

move(BigArr[I+1],BigArr[1],sizeof(BigArr));

end;


For I := 1 to NumofStringsdo


st := GetCompressedString(Arr);

For I := 1 to NumofStringsdo


Writeln(st);

end;


end.



 
请问谁有字符串压缩/解压缩的函数? (100分)
分类:非技术问题 DNChen (1999-03-06 17:09:00)
要求是压缩可以复杂,可以是构件
解压缩必须源程序,而且代码越简练越好

同时注意是压缩字符串,而不是压缩文件!

WebBar (1999-03-06 18:08:00)
《最新C语言应用技术199例》上的 490 页。
用 LZW 算法, 很不错的

delphi fan2 (1999-03-08 0:05:00)
?

D4 (1999-06-09 23:32:00)
先找个字串做密匙char。
然后把要加密的的string xor char不就行了!

yanghaijun (1999-06-10 0:53:00)
你可到<a href="http://www.csdn.net">程序员开发网络</a>去看看,无论是
源码,还是控件都有。

tqz (1999-06-10 9:05:00)
Delphi安装盘的Extra子目录下不是有一个压缩/解压的类吗?有源码,是c的。
封装成Stream了,还很好用的。

huizhang (1999-06-10 10:05:00)
Delphi自带了一个ZLIB.DCU,其中有两个过程可用来压缩字符串:
Uses ZLIB;
...

zlib.CompressBuf(const InBufer: pointer;
InBytes: integer;
out OutBuffer: Pointer;
OutBytes: Integer);
zlib.DeCompressBuf(const InBufer: pointer;
InBytes: integer;

outEstimat: integer;
out OutBuffer: Pointer;
OutBytes: Integer);


DNChen (1999-06-10 22:47:00)
我的要求很奇怪,其实我是想用脚本语言来写解压缩,所以无法调用Delphi Unit

Jams (1999-06-11 2:07:00)
清华大学出版的“数据结构”一书中有关于字符串的压缩的算法,可以去看看!?

曹晓钢 (1999-08-29 0:53:00)
多人接受答案了。


DNChen-50,huizhang-25,tqz-25,的回答最终被接受。
 
200分:求字符串压缩函数 (200分)
分类:数据库-文件型 amengdewo (2003-04-24 14:01:00)
amengdewo@vip.sina.com.cn

远帆 (2003-04-24 14:03:00)
unit MYLZWLITE;

interface

uses
Windows, Messages, SysUtils, Classes;

{
LZW 的变种版本 实现速度很高
只是压缩率就不大了 呵呵 还是有些用的吧


Var LZ:TLZWlite;

Src,Dst:TmemoryStream;

begin

LZ:=TLZWlite.Create;

Src:=TmemoryStream.Create;

Dst:=TmemoryStream.Create;

Src.LoadFromFile('D:/1.bmp');

LZ.CompressToStream(Src.Memory,Dst,Src.Size);

Caption:=Inttostr(Src.Size) +' ->
' +Inttostr(Dst.Size);

Dst.Free;

Src.Free;

LZ.Free;

}


//////////////////////////////////////////////////////////////////////////
// //
// //
// Lempel-Ziv &
Weleh 算法 //
// //
// GGCAT 改编以进行非常快速的压缩处理 //
// //
// 主要改动 小的列表窗口 1024 ( 原为 4096 ) //
// 定长编码输出 方便的快速合并和拆分 //
// //
// 性 能 CA 333 Win2000 >
4M Bytes /PerSecond //
// //
// 压 缩 率 WinZip SuperFast 方式的 120 % //
// 2000-12-20 //
// //
// //
//////////////////////////////////////////////////////////////////////////


Const _WinSize= 1023;
//采用小的窗口 牺牲一定的压缩量换取压缩速度 并减少内存使用
_ClearWnd= 256;
_EndOfData= 257;

Type

TProcessingEvent=Procedure(InPutSize,OutPutSize,Percent:Integer;Var Cancel:Boolean) of Object;


PLZWNode=^TLZWNode;
TLZWNode=Record
Value:Byte;
//本单元包含数据
Index:SmallInt;
//本单元的索引
NodeHigh:SmallInt;
//子接点上标
SubNode:Array[0..255] of SmallInt;
//子接点定位列表
end;


TInt32Array=Array [0..1] of Integer;
PInt32Array=^TInt32Array;

TLZWlite=Class
Private
LZWTree:Array [-1.._WinSize] OF PLZWNode;
CurrentNode:PLZWNode;
WinPos:Smallint;
Procedure ResetTable;
Public
Function CompressToStream(Src:Pointer;MemStream:Tmemorystream;SrcSize:Integer):Integer;
Function DeCompressToStream(Src:Pointer;MemStream:Tmemorystream;SrcSize:Integer):Integer;
Constructor Create;
Destructor Destroy;
Override;
end;


Implementation

Constructor TLZWlite.Create;
Var I:Integer;
begin

Inherited Create;

For I:=-1 to _WinSizedo
//初始化列表
begin

New(LZWTree);
//申请接点
LZWTree.NodeHigh:=-1;
IF I>=0 then
LZWTree.Value:=I;
IF I>=0 then
LZWTree.Index:=I;
end;

LZWTree[-1].NodeHigh:=255;
//定义根接点
For I:=0 to 255do

LZWTree[-1].SubNode:=I;
end;


Destructor TLZWlite.Destroy;
Var I:Integer;
begin

For I:=-1 to _WinSizedo
//退出时释放各个接点
begin

DisPose(LZWTree);
end;

Inherited Destroy;
end;


Procedure TLZWlite.ResetTable;
Var I:Integer;
begin

For I:=0 To _WinSizedo

LZWTree.NodeHigh:=-1;
WinPos:=258;
CurrentNode:=LZWTree[-1];
end;



Function TLZWlite.CompressToStream(Src:Pointer;MemStream:Tmemorystream;SrcSize:Integer):Integer;
VAR SrcData:PByteArray;
OB,H:Integer;
I,J:Integer;
Found,JustComplete:Boolean;
DW,Dstbegin
,DstPtr:Dword;

Procedure OutV(Value:Integer);
Asm
Mov EDX,Value
Inc OB
And OB,3

Cmp OB,1
Je @OB1
Cmp OB,2
Je @OB2
Cmp OB,3
Je @OB3
@OB0:Mov ECX, DstPtr
Mov EAX,EDX
Shr AX,8
OR EAX,DW
Mov [ECX],EAX
Add ECX,4
Mov [Ecx],DL
Inc ECX
Mov DstPtr,Ecx
Jmp @Exit
@OB1:Shl EDX,22
Mov DW,EDX
Jmp @Exit
@OB2:Shl EDX,12
Or DW,EDX
Jmp @Exit
@OB3:Shl EDX,2
Or DW,EDX
@Exit:
end;

begin

SrcData:=Src;
MemStream.Clear;
MemStream.SetSize(SrcSize *10 div 8 +1024);
Dstbegin
:=DWord(MemStream.Memory);
DstPtr:=DWord(MemStream.Memory);
PDword(DstPtr)^:=SrcSize;
Inc(DstPtr,4);

OB:=0;
ResetTable;
OutV(_ClearWnd);
JustComplete:=False ;

For I:=0 to SrcSize-1do

begin

Found:=False;
For J:=0 To CurrentNode.NodeHighdo
// 在树中反复嵌套定位
IF SrcData=LZWTree[CurrentNode.SubNode[J]].Value then

begin

CurrentNode:=LZWTree[CurrentNode.SubNode[J]];
Found:=True;
Break;
end;

IF Found then
Continue;

OutV(CurrentNode.Index);

Inc(CurrentNode.NodeHigh);
//添加新节点并设置接点关联
H:=CurrentNode.NodeHigh;
CurrentNode.SubNode[H]:=WinPos;
LZWTree[WinPos].Value:=SrcData;
CurrentNode:=LZWTree[SrcData];

Inc(WinPos);
//窗口是否超出大小
IF WinPos>_WinSize then

begin

OutV(SrcData);
ResetTable;
//树清零
OutV(_ClearWnd);
IF I=SrcSize-1 then
JustComplete:=True;
//是否恰好结束 以避免重复添加数据
end;

end;


IF Not JustComplete then
OutV(CurrentNode.Index);
//输出最后的字符
OutV(_EndOfData);

IF OB>0 then

For I:=1 to 4-OBdo
OutV(0);

MemStream.SetSize(DstPtr-Dstbegin
);
Result:=MemStream.Size;
MemStream.Position:=0;
end;


Function TLZWlite.DeCompressToStream(Src:Pointer;MemStream:Tmemorystream;SrcSize:Integer):Integer;
Var OutSize,I,J,OB,H,OS:Integer;
Code,OldCode:Smallint;
ThisPackDW,DataPtr,DstPtr:DWord;
ThisPackByte:Byte;
StringTable:Array [0.._WinSize] of Array of Byte;
SLTable:Array [0.._WinSize] of SmallInt;

Procedure GetNextValue;
//数据单元拆分
Asm
CMP OB,1
JE @OB1
CMP OB,2
JE @OB2
CMP OB,3
JE @OB3
@OB0: Mov ECX,DataPtr
MOV EDX,[ECX]
Add ECX,4
Mov ThisPackDW,EDX
MOV AL,[ECX]
Inc ECX
Mov DataPtr,ECX
Mov ThisPackByte,AL
Shr EDX,22
Mov Code,DX
Jmp @Exit
@OB1: Mov EAX,ThisPackDW
Shr EAX,12
AND EAX,$3FF
Mov Code,AX
Jmp @Exit
@OB2: Mov EAX,ThisPackDW
Shr EAX,2
AND EAX,$3FF
Mov Code,AX
Jmp @Exit
@OB3: Mov EAX,ThisPackDW
Shl EAX,8
MOV AL,ThisPackByte
AND EAX,$3FF
Mov Code,AX
@Exit:Inc OB
AND OB,3

end;


Procedure OutValue(Index:Smallint);
//输出对应列表的连续数据
Var I:Integer;
begin

For I:=0 to SLTable[Index]-1do

begin

PByte(DstPtr)^:=StringTable[Index,I];
Inc(DstPtr);
Inc(OS);
end;


end;


begin

OB:=0;
OS:=0;
DataPtr:=DWord(Src);
OutSize:=PDWord(DataPtr)^;
Inc(DataPtr,4);

MemStream.SetSize(OutSize);
DstPtr:=DWord(MemStream.Memory);
WinPos:=258;

For I:=0 To _WinSizedo

begin

IF I<=258 then

SetLength(StringTable,1) else

SetLength(StringTable,I-256);
IF I<=255 then

begin

StringTable[0]:=I;
SLTable:=1;
ENd else

SLTable:=0;
end;

GetNextValue;
While Code<>_EndofDatado

begin

IF Code=_ClearWnd then

begin

WinPos:=258;
GetNextValue;
IF Code=_EndofData then
Break ;
OutValue(Code);
OldCode:=Code;
End else

begin

IF Code<WinPos then

begin

OutValue(Code);
H:=SLTable[OldCode];
SLTable[WinPos]:=H+1;
For J:=0 to H-1do

StringTable[WinPos][J]:=StringTable[OldCode][J];
StringTable[WinPos][H]:=StringTable
代码:
[0];
                  Inc(WinPos);
                  OldCode:=Code;
                End else

                  begin

                    H:=SLtable[OldCode];
                    SLTable[WinPos]:=H+1;
                     For J:=0 to H-1do

                       StringTable[WinPos][J]:=StringTable[OldCode][J];
                    StringTable[WinPos][H]:=StringTable[OldCode][0];
                    OutValue(WinPos);
                    Inc(WinPos);
                    OldCode:=Code;
                  end;

             end;

          GetNextValue;
       end;

   IF OS<>OutSize then
 MemStream.SetSize(OS);
   Result:=OS;
   MemStream.Position:=0;
end;



end.



虽然是采用流操作的,但是操作字符串一样很方便。 
 
52free (2003-04-24 14:11:00)  
记不得在哪儿找到的了

标题: 字符串压缩算法

Contributor: SWAG SUPPORT TEAM

{You won't get that sort of compression from my routines, but here

they are anyway. When testing, you'll get best compression if you

use English and longish Strings.

}

Unit Compress;

Interface

Const

CompressedStringArraySize = 500;
{ err on the side of generosity }

Type

tCompressedStringArray = Array[1..CompressedStringArraySize] of Byte;

Function GetCompressedString(Arr : tCompressedStringArray) : String;

Procedure CompressString(st : String;
Var Arr : tCompressedStringArray;

Var len : Integer);

{ converts st into a tCompressedStringArray of length len }

Implementation

Const

FreqChar : Array[4..14] of Char = 'etaonirshdl';

{ can't be in [0..3] because two empty bits signify a space }

 

Function GetCompressedString(Arr : tCompressedStringArray) : String;

Var

Shift : Byte;

I : Integer;

ch : Char;

st : String;

b : Byte;

Function GetHalfNibble : Byte;

begin


GetHalfNibble := (Arr[I] shr Shift) and 3;

if Shift = 0 then
 begin


Shift := 6;

inc(I);

end else
 dec(Shift,2);

end;


begin


st := '';

I := 1;

Shift := 6;

Repeat

b := GetHalfNibble;

if b = 0 then


ch := ' '

else
 begin


b := (b shl 2) or GetHalfNibble;

if b = $F then
 begin


b := GetHalfNibble shl 6;

b := b or GetHalfNibble shl 4;

b := b or GetHalfNibble shl 2;

b := b or GetHalfNibble;

ch := Char(b);

end else


ch := FreqChar[b];

end;


if ch <>
#0 then
 st := st + ch;

Until ch = #0;

GetCompressedString := st;

end;


Procedure CompressString(st : String;
Var Arr : tCompressedStringArray;

Var len : Integer);

{ converts st into a tCompressedStringArray of length len }

Var

I : Integer;

Shift : Byte;

Procedure OutHalfNibble(b : Byte);

begin


Arr[len] := Arr[len] or (b shl Shift);

if Shift = 0 then
 begin


Shift := 6;

inc(len);

end else
 dec(Shift,2);

end;


Procedure OutChar(ch : Char);

Var

I : Byte;

bych : Byte Absolute ch;

begin


if ch = ' ' then


OutHalfNibble(0)

else
 begin


I := 4;

While (I<15) and (FreqChar[I]<>ch)do
 inc(I);

OutHalfNibble(I shr 2);

OutHalfNibble(I and 3);

if I = $F then
 begin


OutHalfNibble(bych shr 6);

OutHalfNibble((bych shr 4) and 3);

OutHalfNibble((bych shr 2) and 3);

OutHalfNibble(bych and 3);

end;


end;


end;


begin


len := 1;

Shift := 6;

fillChar(Arr,sizeof(Arr),0);

For I := 1 to length(st)do
 OutChar(st[I]);

OutChar(#0);
{ end of compressed String signaled by #0 }

if Shift = 6

then
 dec(len);

end;


end.


测试压缩字符串

Contributor: SWAG SUPPORT TEAM

Program TestComp;
{ tests Compression }

{ kludgy test of Compress Unit }

Uses Crt,do
s, Compress;

Const

NumofStrings = 5;

Var

ch : Char;

LongestStringLength,I,j,len : Integer;

Textfname,Compfname : String;

TextFile : Text;

ByteFile : File;

CompArr : tCompressedStringArray;

st : Array[1..NumofStrings] of String;

Rec : SearchRec;

BigArr : Array[1..5000] of Byte;

Arr : Array[1..NumofStrings] of tCompressedStringArray;

begin


Writeln('note: No I/O checking in this test.');

Write('Test ompress or nCompress? ');

Repeat

ch := upCase(ReadKey);

Until ch in ['C','U',#27];

if ch = #27 then
 halt;

Writeln(ch);

if ch = 'C' then
 begin


Writeln('Enter ',NumofStrings,' Strings:');

LongestStringLength := 0;

For I := 1 to NumofStringsdo
 begin


Write(I,': ');

readln(st[I]);

if length(st[I]) >
LongestStringLength then


LongestStringLength := length(st[I]);

end;


Writeln;

Writeln('Enter name of File to store unCompressed Strings in.');

Writeln('ANY EXISTinG File With THIS NAME WILL BE OVERWRITTEN.');

readln(Textfname);

assign(TextFile,Textfname);

reWrite(TextFile);

For I := 1 to NumofStringsdo


Writeln(TextFile,st[I]);

close(TextFile);

Writeln;

Writeln('Enter name of File to store Compressed Strings in.');

Writeln('ANY EXISTinG File With THIS NAME WILL BE OVERWRITTEN.');

readln(Compfname);

assign(ByteFile,Compfname);

reWrite(ByteFile,1);

For I := 1 to NumofStringsdo
 begin


CompressString(st[I],CompArr,len);

blockWrite(ByteFile,CompArr,len);

end;


close(ByteFile);

FindFirst(Textfname,AnyFile,Rec);

Writeln;

Writeln;

Writeln('Size of Text File storing Strings: ',Rec.Size);

Writeln;

Writeln('Using Typed Files, a File of Type String[',

LongestStringLength,

'] would be necessary.');

Writeln('That would be ',

(LongestStringLength+1)*NumofStrings,

' long, including length Bytes.');

Writeln;

FindFirst(Compfname,AnyFile,Rec);

Writeln('Size of the Compressed File: ',Rec.Size);

Writeln;

Writeln('Now erase the Text File, and run this Program again, choosing');

Writeln('nCompress to show that the Compression retains all info.');

end else
 begin
 { ch = 'U' }

Write('Name of Compressed File: ');

readln(Compfname);

assign(ByteFile,Compfname);

reset(ByteFile,1);

blockread(ByteFile,BigArr,Filesize(ByteFile));

close(ByteFile);

For j := 1 to NumofStringsdo
 begin


I := 1;

While BigArr[I] <>
0do
 inc(I);

move(BigArr[1],Arr[j],I);

move(BigArr[I+1],BigArr[1],sizeof(BigArr));

end;


For I := 1 to NumofStringsdo


st[I] := GetCompressedString(Arr[I]);

For I := 1 to NumofStringsdo


Writeln(st[I]);

end;


end.


 
tianjh007 (2003-04-24 14:56:00)  
   Delphi提供了 Zlib.pas和 Zlibconst.pas两个单元文件来解决数据压缩问题,实现了很高的数据压缩比率。这两个文件保存在 Delphi 5.0安装光盘上 /Info/Extras/Zlib目录下,此外,在 Info/Extras/Zlib/Obj目录中还保存了 Zlib.pas单元引用的 Obj文件。

压缩函数
procedure CompressStream(inpStream, outStream: TStream);

var 
  InpBuf, OutBuf: Pointer;

  InpBytes, OutBytes: Integer;

begin
 
  InpBuf := nil;

  OutBuf := nil;

  try 
    GetMem(InpBuf, inpStream.Size);

    inpStream.Position := 0;

    InpBytes := inpStream.Read(InpBuf^, inpStream.Size);

    CompressBuf(InpBuf, InpBytes, OutBuf, OutBytes);

    outStream.Write(OutBuf^, OutBytes);

  finally 
    if InpBuf <>
nil then
 FreeMem(InpBuf);

    if OutBuf <>
nil then
 FreeMem(OutBuf);

  end;


end;



解压缩函数
{ Decompress a stream } 
procedure DecompressStream(inpStream, outStream: TStream);

var 
  InpBuf, OutBuf: Pointer;

  OutBytes, sz: Integer;

begin
 
  InpBuf := nil;

  OutBuf := nil;

  sz     := inpStream.Size - inpStream.Position;

  if sz >
0 then
  
    try 
      GetMem(InpBuf, sz);

      inpStream.Read(InpBuf^, sz);

      DecompressBuf(InpBuf, sz, 0, OutBuf, OutBytes);

      outStream.Write(OutBuf^, OutBytes);

    finally 
      if InpBuf <>
nil then
 FreeMem(InpBuf);

      if OutBuf <>
nil then
 FreeMem(OutBuf);

    end;


  outStream.Position := 0;

end;




 
amengdewo (2003-04-24 15:02:00)  
TO 远帆
  你提供的程序好像编译不通

TO tianjh007
  你把那两个文件发给我好吗?

 
远帆 (2003-04-24 15:05:00)  
哦,想起来了,那段代码是for d5的。 
 
duguqiubai (2004-03-05 14:09:03)  
给位大虾:我需要一个lzw得源码,需要压缩一个tif文件,本人愿出100,请帮忙!我的Email:wangsc@cs.daqing.com

 
app2001 (2004-03-05 14:25:40)  
ftp://61.129.70.192/datanew/20031223145233981.zip
注释 LZW和LZRW压缩算法源代码 -- 作者:Liu Yang老大 
开发语言: Delphi &
Kylix 
简介: LZW和LZRW压缩算法源代码,速度奇快。 
文件大小: 4.853Kb 

 
auleaf (2004-03-05 14:29:07)  
上网上搜一搜,好像有现成的,也有C的dll 
 
duguqiubai (2004-03-05 14:47:12)  
app2001:你好!我下载不了,可否发Email给我,Email:wangsc@cs.daqing.com 谢谢! 
 
app2001 (2004-03-05 14:53:01)  
我发给你了 
 
apw (2004-03-05 15:09:11)  
在这试试看,总有一款适合你。
http://www.vclxx.org/DELPHIGB/AAAT1027.HTM#COMPRESS 
 
孤独之孤 (2004-03-05 19:06:58)  
用DELPHI自带的ZLIB库吧,对字符串压缩效果很好. 
 
dedema (2004-03-05 20:24:13)  
收藏中吧! 
 
远帆 (2004-03-08 12:14:59)  
上面我贴的代码改动一点之后就可以通过,不过楼主好像都不见了?
 
怎么不试一试使用Delphi自己的压缩流呢?
在Zlib单元中
 
晕!楼上的老大,给个连接不就完了吗?垒这么高的楼!
 
谢谢大家
 
多人接受答案了。
 
后退
顶部