#ifndef _221095_165753_huffnode_h #define _221095_165753_huffnode_h #include #include "byte.h" // Type definitions. // class huffnode; typedef unsigned char byte; typedef enum { invalid, leaf, internal } huffnode_type; // huffnode is a node in a huffman tree, either a leaf or an internal node // class huffnode { protected: // Data members // huffnode_type _type; // The type of this node. byte _char; // The character stored in this node if it is a leaf int _count; // The number of occurences of this character if a leaf vector _bits; // The Huffman-bit-string for this character if a leaf huffnode * _left; // The left child if it is an internal node. huffnode * _right; // The right child if it is an internal node. public: // Constructors and Destructors // huffnode() : _type(invalid), _char(0), _left(NULL), _right(NULL), _count(0), _bits() {}; huffnode( const byte& c, int cnt=1 ) : _type(leaf), _char(c), _left(NULL), _right(NULL), _count(cnt), _bits() {}; huffnode( huffnode* l, huffnode* r ) : _type(internal), _char(0), _bits() { // TODO: // Constructor which merges two huffman trees (given their root nodes), // constructing the root node of a single huffman tree, }; ~huffnode() { if( _left ) delete _left; if( _right ) delete _right; }; // Inspectors // huffnode_type type() const { return _type; }; byte character() const { return _char; }; int count() const { return _count; }; huffnode* left() const { return _left; }; huffnode* right() const { return _right; }; const vector& bits() const { return _bits; }; // Modifiers // int set_count( const int newcnt ) { return _count = newcnt; }; friend void destroy(huffnode** p) {}; // REMOVE }; #endif /* _221095_165753_huffnode_h */