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

📄 en_decode.h

📁 实现Huffman编码统计压缩算法
💻 H
字号:
// En_Decode.h: interface for the En_Decode class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_EN_DECODE_H__EFEDB134_3A40_4855_8EA5_828E486E6B35__INCLUDED_)
#define AFX_EN_DECODE_H__EFEDB134_3A40_4855_8EA5_828E486E6B35__INCLUDED_

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

#include <fstream>
#include <cstdlib>
#include <iostream>
#include <cmath>

typedef unsigned int FREQCOUNTER;

struct HufNodeStruc
{
	FREQCOUNTER freq;
	int parent;
	int right;
	int left;
};

const int MaxFileNameLength = 256;

class En_Decode
{
public:
	En_Decode(const char *fin_name, const char *fout_name);
	En_Decode(const char *fin_name);
	En_Decode();
	virtual ~En_Decode();
	void Encode();
	void Decode();
	void SetInputFileName(const char *pathname, const char *extname);
	void SetOutputFileName(const char *pathname);
	void GetExtName(char *extname);
	FREQCOUNTER GetMinFreq();
	FREQCOUNTER GetMaxFreq();
	FREQCOUNTER GetFreq(const int idx);
	int GetActiveSymbols();
	FREQCOUNTER GetActualDataLength();
	FREQCOUNTER GetUncodedFileLength();
	double GetUncodedFileCodeLength();
	double GetSourceFileEntropy();
private:
	void BuildHufTree();
	void Output1Bit(int bit);
	void Compress1Byte(int node, int child);
private:
	std::ofstream out_file;
	HufNodeStruc OurTree[511];
	int NumOfRootNode;
	unsigned char BitContainer;
	unsigned char BitCounter;
	char infile_buf[MaxFileNameLength];
	char outfile_buf[MaxFileNameLength];
	unsigned char EncodedCode[256];
	char ext_name[10];
	unsigned char ext_length;
	int bit_count;

	FREQCOUNTER OrigBytes;
	int ActiveSymbs;
	FREQCOUNTER DestLength;

	void StrCopy(const char *from, char *to);
	unsigned char GetStrLength(const char *str);
};

#endif // !defined(AFX_EN_DECODE_H__EFEDB134_3A40_4855_8EA5_828E486E6B35__INCLUDED_)

⌨️ 快捷键说明

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