FACT++  1.0
bool Huffman::Encoder::CreateEncoder ( const TreeNode n,
size_t  bits = 0,
uint8_t  nbits = 0 
)
inline

Definition at line 87 of file huffman.h.

References Huffman::Encoder::Code::bits, Huffman::TreeNode::isLeaf, Huffman::Encoder::Code::numbits, Huffman::TreeNode::one, Huffman::TreeNode::symbol, and Huffman::TreeNode::zero.

88  {
89  if (n->isLeaf)
90  {
91 #ifdef __EXCEPTIONS
92  if (nbits>sizeof(size_t)*8)
93  throw std::runtime_error("Too many different symbols - this should not happen!");
94 #else
95  if (nbits>sizeof(size_t)*8)
96  {
97  count = 0;
98  return false;
99  }
100 #endif
101  lut[n->symbol].bits = bits;
102  lut[n->symbol].numbits = nbits==0 ? 1 : nbits;
103  count++;
104  return true;
105  }
106 
107  return
108  CreateEncoder(n->zero, bits, nbits+1) &&
109  CreateEncoder(n->one, bits | (1<<nbits), nbits+1);
110 
111  }
Code lut[1<< 16]
Definition: huffman.h:85
bool CreateEncoder(const TreeNode *n, size_t bits=0, uint8_t nbits=0)
Definition: huffman.h:87
size_t count
Definition: huffman.h:84