lzw.h

来自「用C++语言编译的LZW压缩算法」· C头文件 代码 · 共 43 行

H
43
字号
//:LZW.h
#ifndef LZW_H
#define LZW_H

#include <cmath>
#include <iostream>
#include <string>

#define ASCII_SIZE 256
const int MAX = 12;
const int MaxSize = pow(2, MAX);

class LZWException : public std::exception{
public:
	LZWException(const std::string& msg = "") : std::exception(msg.c_str()) {}
};//end LZWException

class LZW{
	long* codes;//A code dictionary
	int size;//The current size of the code dictionary
	int left;//The left of code haven't been outputed
	bool preffix;
public:
	//Constructor and destructor
	LZW();
	~LZW();
	//Public operations
	//Compact the file given by parameter name
	void compact(const std::string& name) throw(LZWException);
	//Decompact the file given by parameter name
	void deCompact(const std::string& name) throw(LZWException);
protected:
	//Protected operations
	//Output the new code to out ostream
	void output(int code, std::ostream& out);
	//Determined whether the item is in the dictionary, if any save its code in parameter code
	bool search(long item, int& code);
	//Output the item specified by code to out ostream
	void deCode(unsigned int code, std::ostream& out);
};//end LZW

#endif//LZW_H
///:~

⌨️ 快捷键说明

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