Huffman Zipper  v-1.0
Data Compression and Decompression using Greedy Huffman Algorithm
BinNode.cpp
Go to the documentation of this file.
1 #include "BinNode.h"
2 
3 BinNode::BinNode(char character) :character(character), frequency(0), leftChild(nullptr), rightChild(nullptr) {}
4 
5 BinNode::BinNode(char character, int frequency) : character(character), frequency(frequency), leftChild(nullptr), rightChild(nullptr) {}
6 
7 std::ostream& operator<<(std::ostream& os, BinNode* node) {
8  os << node->getCharacter() << "=" << node->getFrequency() << std::flush;
9  return os;
10 }
11 
12 std::ostream& operator<<(std::ostream& os, const BinNode& node) {
13  os << node.getCharacter() << "=" << node.getFrequency() << std::flush;
14  return os;
15 }
16 
17 bool BinNode::operator<(const BinNode& other) {
18  return this->getFrequency() < other.getFrequency();
19 }
20 
21 bool BinNode::operator<=(const BinNode& other) {
22  return this->getFrequency() <= other.getFrequency();
23 }
24 
25 char BinNode::getCharacter() const {
26  return character;
27 }
28 
29 int BinNode::getFrequency() const {
30  return frequency;
31 }
32 
34  this->leftChild = left;
35 }
36 
38  this->rightChild = right;
39 }
40 
42  return leftChild;
43 }
44 
46  return rightChild;
47 }
48 
50  return getLeftChild() == nullptr && getRightChild() == nullptr;
51 }
std::ostream & operator<<(std::ostream &os, BinNode *node)
Definition: BinNode.cpp:7
This class models a node structure used for building Huffman Binary Tree.
Definition: BinNode.h:9
bool operator<=(const BinNode &)
This method overloads less than and equal to (<=) operator for comparing node.
Definition: BinNode.cpp:21
BinNode * leftChild
Pointer to the left child.
Definition: BinNode.h:13
int frequency
Number of occurrence of a character.
Definition: BinNode.h:12
BinNode(char)
Definition: BinNode.cpp:3
BinNode * getRightChild() const
Definition: BinNode.cpp:45
BinNode * rightChild
Pointer to the right child.
Definition: BinNode.h:14
void setRightChild(BinNode *)
sets parameter node as left child of the caller node instance.
Definition: BinNode.cpp:37
int getFrequency() const
Definition: BinNode.cpp:29
bool isLeaf()
Definition: BinNode.cpp:49
void setLeftChild(BinNode *)
sets parameter node as left child of the caller node instance.
Definition: BinNode.cpp:33
char character
Character present in input data.
Definition: BinNode.h:11
BinNode * getLeftChild() const
Definition: BinNode.cpp:41
bool operator<(const BinNode &)
This method overloads less than operator for comparing node.
Definition: BinNode.cpp:17
char getCharacter() const
Definition: BinNode.cpp:25