-
Notifications
You must be signed in to change notification settings - Fork 0
/
HCNode.hpp
51 lines (39 loc) · 1.17 KB
/
HCNode.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
47
48
49
50
51
#ifndef HCNODE_HPP
#define HCNODE_HPP
#include <iostream>
typedef unsigned char byte;
using namespace std;
/** A class, instances of which are nodes in an HCTree.
*/
class HCNode {
friend bool comp(HCNode* one, HCNode* other);
public:
//Default destructor
~HCNode();
int count;
byte symbol; // byte in the file we're keeping track of
HCNode* c0; // pointer to '0' child
HCNode* c1; // pointer to '1' child
HCNode* p; // pointer to parent
HCNode(int count,
byte symbol,
HCNode* c0 = 0,
HCNode* c1 = 0,
HCNode* p = 0)
: count(count), symbol(symbol), c0(c0), c1(c1), p(p) { }
/** Less-than comparison, so HCNodes will work in std::priority_queue
* We want small counts to have high priority.
* And we want to break ties deterministically.
*/
bool operator<(const HCNode& other);
};
/** For printing an HCNode to an ostream
* Possibly useful for debugging.
*/
ostream& operator<<(ostream&, const HCNode&) __attribute__((weak)); // shut the linker up
ostream& operator<<(ostream& stm, const HCNode& n) {
stm << "[" << n.count << "," << (int) (n.symbol) << "]";
return stm;
}
bool comp(HCNode* one, HCNode* other);
#endif // HCNODE_HPP