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

📄 lzw.h

📁 用C++语言编译的LZW压缩算法
💻 H
字号:
//: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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -