⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compressarithmetic.h

📁 很好用的压缩和解压缩程序
💻 H
字号:
// CompressArithmetic.h: interface for the CCompressArithmetic class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_COMPRESSARITHMETIC_H__3375B5FC_A9F1_4BEE_AA1B_66FB5E4DCB37__INCLUDED_)
#define AFX_COMPRESSARITHMETIC_H__3375B5FC_A9F1_4BEE_AA1B_66FB5E4DCB37__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define INIT_BITS	9 //初始编码大小
#define MAX_BITS	14 //最大编码大小 
#define HASHING_SHIFT MAX_BITS - 8	//哈希位移

#if MAX_BITS == 14            
#define TABLE_SIZE 18041	/* 编码表大小. 必须是一个大于2^MAX_S的素数*/
#elif MAX_BITS == 13
#define TABLE_SIZE 9029
#else
#define TABLE_SIZE 5021
#endif

#define CLEAR_TABLE 256    /* 表满刷新标志 */
#define TERMINATOR  257    /* 解码结束标志 */
#define FIRST_CODE  258    /* 编码表中第一个有效编码 */
#define CHECK_TIME  500    /* Check comp ratio every CHECK_TIME chars input */

#define MAXVAL(n) (( 1 <<( n )) -1)   /* max_value formula macro */

class CCompressArithmetic  
{
private:
	int *code_value;						/* This is the code value array */
	unsigned int *prefix_code;				/* This array holds the prefix codes */
	unsigned char *append_character;		/* This array holds the appended chars */
	unsigned char *decode_stack;			/* This array holds the decoded string */


	int num_bits;							/* Starting with 9 bit codes */
	unsigned long bytes_in,bytes_out;		/* Used to monitor compression ratio */
	unsigned int max_code;					/* old MAX_CODE */
	unsigned long checkpoint;				/* For compression ratio monitoring */
	unsigned long incounts;
	unsigned long outcounts;
	unsigned long counts;
	unsigned char *input,*output;
	int input_bit_count;
	unsigned long input_bit_buffer;
	int output_bit_count;
	unsigned long output_bit_buffer;

	bool bFlagAlloc;
public:
	void compress();
	void uncompress();
	bool init(unsigned char *inputs,unsigned long lens,unsigned char *outputs);
private:
	int find_match(unsigned int hash_prefix, unsigned int hash_character);
	void output_code(unsigned int code);
	unsigned input_code();
	unsigned char *decode_string(unsigned char *buffer, unsigned int code);
public:
	void FreeTables();
	bool AllocTables(void);
	unsigned long GetInBytes();
	unsigned long GetOutBytes();
	CCompressArithmetic();
	virtual ~CCompressArithmetic();
};

#endif // !defined(AFX_COMPRESSARITHMETIC_H__3375B5FC_A9F1_4BEE_AA1B_66FB5E4DCB37__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -