-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHCNode.h
executable file
·58 lines (47 loc) · 1.49 KB
/
HCNode.h
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
52
53
54
55
56
57
58
/****************************************************************************
*
* Kening Zhang, Gang Yang
* CSE 100, fall 17
* 11/9/2017
* cs100fje cs100fiy
*
* Assignment 3
* Filename: HCNode.h
* Description: set the public private field, and method of node
***************************************************************************/
#ifndef HCNODE_H
#define HCNODE_H
#include <iostream>
typedef unsigned char byte;
using namespace std;
/** A class, instances of which are nodes in an HCTree.
*/
class HCNode {
public:
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;
}
#endif // HCNODE_H