FACT++  1.0
Huffman::Encoder::Encoder ( const uint16_t *  bufin,
size_t  bufinlen 
)
inline

Definition at line 187 of file huffman.h.

References counts, i, MAX_SYMBOLS, size, and Huffman::TreeNode::TreeNode().

187  : count(0)
188  {
189  uint64_t counts[MAX_SYMBOLS];
190  memset(counts, 0, sizeof(uint64_t)*MAX_SYMBOLS);
191 
192  // Count occurances
193  for (const uint16_t *p=bufin; p<bufin+bufinlen; p++)
194  counts[*p]++;
195 
196  // Copy all occuring symbols into a sorted list
197  std::multiset<TreeNode*, TreeNode> set;
198  for (int i=0; i<MAX_SYMBOLS; i++)
199  if (counts[i])
200  set.insert(new TreeNode(i, counts[i]));
201 
202  // Create the tree bottom-up
203  while (set.size()>1)
204  {
205  auto it = set.begin();
206 
207  auto it1 = it++;
208  auto it2 = it;
209 
210  TreeNode *nn = new TreeNode(*it1, *it2);
211 
212  set.erase(it1, ++it2);
213 
214  set.insert(nn);
215  }
216 
217  // get the root of the tree
218  const TreeNode *root = *set.begin();
219 
220  CreateEncoder(root);
221 
222  // This will delete the whole tree
223  delete root;
224  }
#define MAX_SYMBOLS
Definition: huffman.h:11
int i
Definition: db_dim_client.c:21
bool CreateEncoder(const TreeNode *n, size_t bits=0, uint8_t nbits=0)
Definition: huffman.h:87
size_t count
Definition: huffman.h:84
int size
Definition: db_dim_server.c:17
uint32_t counts
Definition: HeadersSQM.h:91

+ Here is the call graph for this function: