-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuffmanBase.cpp
More file actions
executable file
·41 lines (33 loc) · 841 Bytes
/
HuffmanBase.cpp
File metadata and controls
executable file
·41 lines (33 loc) · 841 Bytes
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
#include "HuffmanBase.hpp"
char HuffmanNode::getCharacter() const
{
return character;
}
size_t HuffmanNode::getFrequency() const
{
return frequency;
}
bool HuffmanNode::isLeaf() const
{
return (left == nullptr && right == nullptr);
}
bool HuffmanNode::isBranch() const
{
return (left != nullptr || right != nullptr);
};
bool HuffmanNode::isRoot() const
{
return (parent == nullptr);
};
bool HuffmanNode::Compare::operator()(const HuffmanNode &n1, const HuffmanNode &n2) const
{
if (n1.frequency == n2.frequency) {
return lessThan ? n1.character < n2.character : n1.character >= n2.character;
} else {
return lessThan ? n1.frequency < n2.frequency : n1.frequency >= n2.frequency;
}
}
bool HuffmanNode::Compare::operator()(const HuffmanNode *n1, const HuffmanNode *n2) const
{
return operator()(*n1, *n2);
}