Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
huffmanCoding/Huffman.H
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
54 lines (37 sloc)
1.21 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __HUFFMAN_H__ | |
#define __HUFFMAN_H__ | |
#include <map> | |
#include <memory> | |
#include <string> | |
#include <stdlib.h> | |
using namespace std; | |
struct Node; | |
class Huffman { | |
protected: | |
std::string _fname; | |
std::shared_ptr<Node> _tree; | |
std::map<char,std::string> _bitMap; | |
void generateBitMapHelper(shared_ptr<Node> curr, string bin); | |
public: | |
Huffman(string fname): _fname(fname) , _bitMap(){} | |
virtual ~Huffman(){} | |
virtual void generateTree(){};// Will be different for compress and decompress | |
void generateBitMap(); | |
void printBitMap(); | |
void printPreorder(); | |
const map<char,string> & getBitMap(){ return _bitMap;} | |
string getFileName(){return _fname;} | |
}; | |
struct Node{ | |
double value; | |
char letter; | |
std::shared_ptr<Node> left; | |
std::shared_ptr<Node> right; | |
Node(double _value, char _letter, std::shared_ptr<Node> _left, std::shared_ptr<Node> _right) : value(_value), letter(_letter), left(_left), right(_right) {} | |
bool isLeaf(){return (!left && !right);} | |
}; | |
string convertToBits(string uncompressed);//Converts the string format bits into char | |
string convertToString(string compressed);//Converts the bit form into string form | |
template <class Ptr> | |
string preOrder(Ptr curr,string &lett); | |
#endif |