-
Notifications
You must be signed in to change notification settings - Fork 0
/
HuffmanBase.hpp
46 lines (37 loc) · 1.14 KB
/
HuffmanBase.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef HUFFMANBASE_H
#define HUFFMANBASE_H
#include <cstddef>
#include <string>
#include <iostream>
class HuffmanNode {
public:
HuffmanNode(char c, size_t f, HuffmanNode *p, HuffmanNode *l, HuffmanNode *r) : character(c), frequency(f), parent(p), left(l), right(r) {};
HuffmanNode(char c, size_t f) : HuffmanNode(c, f, nullptr, nullptr, nullptr) {};
char getCharacter() const;
size_t getFrequency() const;
bool isLeaf() const;
bool isBranch() const;
bool isRoot() const;
class Compare {
public:
Compare(bool lessThan = true) : lessThan(lessThan) {};
bool operator()(const HuffmanNode &n1, const HuffmanNode &n2) const;
bool operator()(const HuffmanNode *n1, const HuffmanNode *n2) const;
private:
bool lessThan;
};
private:
char character;
size_t frequency;
public:
HuffmanNode *parent;
HuffmanNode *left;
HuffmanNode *right;
};
class HuffmanTreeBase {
public:
virtual std::string compress(const std::string inputStr) = 0;
virtual std::string serializeTree() const = 0;
virtual std::string decompress(const std::string inputCode, const std::string serializedTree) = 0;
};
#endif /* HUFFMANBASE_H */