实验名称:LZSS压缩算法实验报告一、实验内容使用Visual60C编程实现LZ77压缩算法。二、实验目的用LZSS实现文件的压缩。三、实验原理
LZSS压缩算法是词典编码无损压缩技术的一种。LZSS压缩算法的字典模型使用了自适应的方式,也就是说,将已经编码过的信息作为字典,四、实验环境1、软件环境:VisualC602、编程语言:C五、实验代码
i
cludestdlibhi
cludestri
ghi
cludectypehi
cludestdioh
sizeofri
gbuffer
defi
eN
4096
i
dexforrootofbi
arysearchtrees
defi
eNIL
N
upperlimitforg_match_le
Cha
gedfrom18to16forbi
ary
compatabilitywithMicrosoftCOMPRESSEXEa
dEXPANDEXE
defi
eF
18
defi
eF
16
e
codestri
gi
topositio
a
dle
gth
ifmatch_le
gthisgreatertha
this
defi
eTHRESHOLD2
theseassumelittlee
dia
CPUlikeI
telx86
f
eedbyteswapfu
ctio
forbige
dia
CPUdefi
eREAD_LE32Xui
t32_tXdefi
eWRITE_LE32XYui
t32_tXY
thisassumessizeoflo
g4typedefu
sig
edlo
gui
t32_t
texti
putsizecou
tercodeoutputsizecou
tera
dcou
terforreporti
gprogressevery1Kbytesstaticu
sig
edlo
gg_text_sizeg_code_sizeg_pri
t_cou
tri
gbufferofsizeNwithextraF1bytestofacilitatestri
gcompariso
staticu
sig
edcharg_ri
g_bufferNF1positio
a
dle
gthoflo
gestmatchsetbyi
sert_
odestaticu
sig
edg_match_posg_match_le
leftrightchildre
pare
ttheseco
stitutebi
arysearchtreestaticu
sig
edg_left_childN1g_right_childN257g_pare
tN1i
putoutputfilesstaticFILEg_i
fileg_outfilei
itializetreesstaticvoidi
it_treevoid
u
sig
edi
Fori0toN1g_right_childia
dg_left_childiwillbetherighta
dleftchildre
of
odeiThese
odes
eed
otbei
itializedAlsog_pare
tiisthepare
tof
odeiThesearei
itializedtoNILNwhichsta
dsfor
otusedFori0to255g_right_childNi1istherootofthetreeforstri
gsthatbegi
withcharacteriThesearei
itializedtoNILNotethereare256treesforiN1iN256ig_right_childiNILfori0iNig_pare
tiNIL
I
sertsstri
gofle
gthFg_ri
g_bufferrrF1i
too
eofthetreesg_ri
g_bufferrthtreea
dretur
sthelo
gestmatchpositio
a
dle
gthviatheglobalvariablesg_match_posa
dg_match_le
Ifg_match_le
Fthe
removestheold
odei
favorofthe
ewo
ebecausetheoldo
ewillbedeletedsoo
er
fNoterplaysdoubleroleastree
odea
dpositio
i
bufferr