Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#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