lzss的c语言程序免费下载,LZSS压缩算法C语言实现.doc

/*----------------------------------------------------------------------------

LZSS.C -- A Data Compression Program

4/6/1989 Haruhiko Okumura

Use, distribute, and modify this program freely.

Please send me your improved versions.

PC-VANSCIENCE

NIFTY-ServePAF01022

CompuServe74050,1022

Some changes made June, 2003 by Chris Giese

, /~geezer

- Changed F from 16 to 18, for compatability with Microsoft COMPRESS/EXPAND

EXPAND.EXE is on the install disks for MS-DOS version 6 and Windows 3.1

COMPRESS.EXE is in the Win 3.1 SDK, and comes with Borland C++ 3.1

- Changed compress/expand chars on command line from e/d to c/u

- Where possible and correct, changed ints to unsigned

- Made all functions static

- Changed formatting, indenting, global variable names, and function names

- Tried to simplify/clarify code in some areas

----------------------------------------------------------------------------*/

#include

#include

#include

#include

/* size of ring buffer */

#defineN4096

/* index for root of binary search trees */

#define NILN

/* upper limit for g_match_len. Changed from 18 to 16 for binary

compatability with Microsoft COMPRESS.EXE and EXPAND.EXE

#defineF18 */

#defineF16

/* encode string into position and length

if match_length is greater than this: */

#defineTHRESHOLD2

/* these assume little-endian CPU like Intel x86

-- need byte-swap function for big endian CPU */

#defineREAD_LE32(X)*(uint32_t *)(X)

#defineWRITE_LE32(X,Y)*(uint32_t *)(X) = (Y)

/* this assumes sizeof(long)==4 */

typedef unsigned longuint32_t;

/* text (input) size counter, code (output) size counter,

and counter for reporting progress every 1K bytes */

static unsigned long g_text_size, g_code_size, g_print_count;

/* ring buffer of size N, with extra F-1 bytes

to facilitate string comparison */

static unsigned char g_ring_buffer[N + F - 1];

/* position and length of longest match; set by insert_node() */

static unsigned g_match_

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LZSS(Lempel-Ziv-Sliding-Window-Algorithm)是一种用于无损数据压缩算法。它是基于LZ77算法的改进版本,主要用于压缩文本或者具有重复字符的数据。 LZSS算法实现可以使用C语言。在这个算法中,首先需要定义两个指针,一个用于查找历史字典窗口中的匹配字符串,另一个用于扫描输入字符串并生成输出编码。 算法的核心步骤如下: 1. 初始化字典窗口和输入字符串的指针。 2. 从输入字符串中取一个字符,并在字典窗口中寻找最长的与之匹配的字符串。 3. 如果找到匹配的字符串,将其以指针(偏移)和长度的形式输出,并将指针移到匹配字符串之后的位置。 4. 如果没有找到匹配的字符串,则将当前字符直接输出,并将指针向前移动一位。 5. 重复步骤2~4,直到输入字符串全部处理完毕。 6. 输出最后的结束标志。 在C语言中,可以使用数组来实现字典窗口和输入字符串的存储。可以定义一个字符数组作为字典窗口,用以保存历史的已编码字符串。同时,也需要定义一个字符数组作为输入字符串。 通过循环遍历输入字符串并比较字典窗口中的字符串,可以找到最长的匹配字符串。然后,根据匹配字符串的指针和长度输出对应的编码。 需要注意的是,为了提高算法效率,可以采用哈希表等数据结构来加速字符串的匹配过程。 总之,LZSS算法是一种用于无损数据压缩算法,利用历史字典窗口和输入字符串之间的匹配来实现压缩。在C语言中,可以使用数组和循环遍历等基本操作来实现算法

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值