📄 lzh.h
字号:
#ifndef _LZH_H_
#define _LZH_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define EXIT_OK 0
#define EXIT_FAILED -1
#define N 4096 /* Size of string buffer */
#define F 60 /* Size of look-ahead buffer */
#define THRESHOLD 2
#define NIL N /* End of tree's node */
#define N_CHAR (256 - THRESHOLD + F)
/* character code (= 0..N_CHAR-1) */
#define T (N_CHAR * 2 - 1) /* Size of table */
#define R (T - 1) /* root position */
#define MAX_FREQ 0x8000
/* update when cumulative frequency */
/* reaches to this value */
typedef unsigned char uchar;
/*
* Tables for encoding/decoding upper 6 bits of
* sliding dictionary pointer
*/
/* encoder table */
class FileEncodeDecode
{
private:
char *infile, *outfile;
unsigned long textsize, codesize, printcount;
unsigned char text_buf[N + F - 1], getlen, putlen;
short match_position, match_length,
lson[N + 1], rson[N + 257], dad[N + 1];
unsigned short freq[T + 1]; /* cumulative freq table */
short prnt[T + N_CHAR];
short son[T];
unsigned short getbuf, putbuf, code, len;
unsigned short posOut, posIn;
long countEncoded;
private:
void Error(char *message)
{
printf( "%s\n", message );
};
void InitTree( void );
void InsertNode( short r );
void DeleteNode( short p );
short GetBit(void); /* get one bit */
short GetByte(void); /* get a byte */
void Putcode(short l, unsigned short c); /* output c bits */
void StartHuff(void);
void reconst(void);
void update(short c);
void EncodeChar(unsigned short c);
void EncodePosition(unsigned short c);
void EncodeEnd(void);
short DecodeChar(void);
short DecodePosition(void);
short Putc(short putBuf, char *outFile);
short Getc(char *inFile);
public:
FileEncodeDecode(char *i_file, char *o_file,long count_file);
~FileEncodeDecode();
long Encode(void); /* Encoding/Compressing */
long Decode(void); /* Decoding/Uncompressing */
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -