ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:31.09KB ,
资源ID:10573723      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10573723.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(LZSS压缩算法实验报告.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

LZSS压缩算法实验报告.docx

1、LZSS压缩算法实验报告实验名称:LZSS压缩算法实验报告一、实验内容使用Visual 6.0 C+编程实现LZ77压缩算法。二、实验目的用LZSS实现文件的压缩。三、实验原理LZSS压缩算法是词典编码无损压缩技术的一种。LZSS压缩算法的字典模型使用了自适应的方式,也就是说,将已经编码过的信息作为字典,四、实验环境1、软件环境:Visual C+ 6.02、编程语言:C+五、实验代码#include #include #include #include /* size of ring buffer */#define N 4096/* index for root of binary sea

2、rch trees */#define NIL N/* upper limit for g_match_len. Changed from 18 to 16 for binarycompatability with Microsoft COMPRESS.EXE and EXPAND.EXE#define F 18 */#define F 16/* encode string into position and lengthif match_length is greater than this: */#define THRESHOLD 2/* these assume little-endia

3、n CPU like Intel x86- need byte-swap function for big endian CPU */#define READ_LE32(X) *(uint32_t *)(X)#define WRITE_LE32(X,Y) *(uint32_t *)(X) = (Y)/* this assumes sizeof(long)=4 */typedef unsigned long uint32_t;/* text (input) size counter, code (output) size counter,and counter for reporting pro

4、gress every 1K bytes */static unsigned long g_text_size, g_code_size, g_print_count;/* ring buffer of size N, with extra F-1 bytesto facilitate string comparison */static unsigned char g_ring_bufferN + F - 1;/* position and length of longest match; set by insert_node() */static unsigned g_match_pos,

5、 g_match_len;/* left & right children & parent - these constitute binary search tree */static unsigned g_left_childN + 1, g_right_childN + 257, g_parentN + 1;/* input & output files */static FILE *g_infile, *g_outfile;/*initialize trees*/static void init_tree(void) unsigned i;/* For i = 0 to N - 1,

6、g_right_childi and g_left_childi will be the right and left children of node i. These nodes need not be initialized. Also, g_parenti is the parent of node i. These are initialized to NIL (= N), which stands for not used. For i = 0 to 255, g_right_childN + i + 1 is the root of the tree for strings th

7、at begin with character i. These are initialized to NIL. Note there are 256 trees. */ for(i = N + 1; i = N + 256; i+) g_right_childi = NIL; for(i = 0; i = 0) if(g_right_childp != NIL) p = g_right_childp; else g_right_childp = r; g_parentr = p; return; else if(g_left_childp != NIL) p = g_left_childp;

8、 else g_left_childp = r; g_parentr = p; return; for(i = 1; i g_match_len) g_match_pos = p; g_match_len = i; if(g_match_len = F) break; g_parentr = g_parentp; g_left_childr = g_left_childp; g_right_childr = g_right_childp; g_parentg_left_childp = r; g_parentg_right_childp = r; if(g_right_childg_paren

9、tp = p) g_right_childg_parentp = r; else g_left_childg_parentp = r; g_parentp = NIL; /* remove p */*deletes node p from tree*/static void delete_node(unsigned p) unsigned q; if(g_parentp = NIL) return; /* not in tree */ if(g_right_childp = NIL) q = g_left_childp; else if(g_left_childp = NIL) q = g_r

10、ight_childp; else q = g_left_childp; if(g_right_childq != NIL) do q = g_right_childq; while(g_right_childq != NIL); g_right_childg_parentq = g_left_childq; g_parentg_left_childq = g_parentq; g_left_childq = g_left_childp; g_parentg_left_childp = q; g_right_childq = g_right_childp; g_parentg_right_ch

11、ildp = q; g_parentq = g_parentp; if(g_right_childg_parentp = p) g_right_childg_parentp = q; else g_left_childg_parentp = q; g_parentp = NIL;/*/static void compress(void) unsigned i, len, r, s, last_match_length, code_buf_ptr; unsigned char code_buf17, mask; int c; init_tree(); /* initialize trees */

12、* code_buf1.16 saves eight units of code, and code_buf0 works aseight flags, 1 representing that the unit is an unencoded letter (1 byte),0 a position-and-length pair (2 bytes). Thus, eight units require at most16 bytes of code. */ code_buf0 = 0; code_buf_ptr = mask = 1; s = 0; r = N - F;/* Clear th

13、e buffer with any character that will appear often. */ memset(g_ring_buffer + s, , r - s);/* Read F bytes into the last F bytes of the buffer */ for(len = 0; len F; len+) c = getc(g_infile); if(c = EOF) break; g_ring_bufferr + len = c; g_text_size = len; if(g_text_size = 0) /* text of size zero */ r

14、eturn;/* Insert the F strings, each of which begins with one or more spacecharacters. Note the order in which these strings are inserted.This way, degenerate trees will be less likely to occur. */ for(i = 1; i len) g_match_len = len;/* Not long enough match. Send one byte. */ if(g_match_len THRESHOL

15、D. */ else code_bufcode_buf_ptr = (unsigned char)g_match_pos; code_buf_ptr+; code_bufcode_buf_ptr = (unsigned char) (g_match_pos 4) & 0xF0) | (g_match_len - (THRESHOLD + 1); code_buf_ptr+; /* Shift mask left one bit. */ mask = 1; if(mask = 0) /* Send at most 8 units of code together */ for(i = 0; i

16、code_buf_ptr; i+) putc(code_bufi, g_outfile); g_code_size += code_buf_ptr; code_buf0 = 0; code_buf_ptr = mask = 1; last_match_length = g_match_len; for(i = 0; i last_match_length; i+) c = getc(g_infile); break;/* Delete old strings and read new bytes */ delete_node(s); g_ring_buffers = c;/* If the p

17、osition is near the end of buffer, extend the bufferto make string comparison easier. */ if(s g_print_count) printf(%12ldr, g_text_size); g_print_count += 1024; while(i+ 0); /* until length of string to be processed is zero */* Send remaining code. */ if(code_buf_ptr 1) for(i = 0; i = 1) /* Get a by

18、te. For each bit of this byte:1=copy one byte literally, from input to output0=get two more bytes describing length and position of previously-seen data, and copy that data from the ring buffer to output */ if(flags & 0x100) = 0) c = getc(g_infile); if(c = EOF) break;/* uses higher byte cleverly to

19、count eight */ flags = c | 0xFF00; /* 1=copy one byte literally, from input to output */ if(flags & 1) c = getc(g_infile); if(c = EOF) break; putc(c, g_outfile); g_ring_bufferr = c; r = (r + 1) & (N - 1); /* 0=get two more bytes describing length and position of previously-seen data, and copy that data from the ring buffer to output */ else i = getc(g_infile); if(i = EOF) break; j = getc(g_infile); if(j = EOF) break; i |= (j & 0xF0) 4); j = (j & 0x0F) + THRESHOL

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1