HuffmanEncoder.cc
// generate symbol frequencies from the given file.
generate symbol frequencies from the given file.
generate symbol frequencies from the given file .
HuffmanEncoder::HuffmanEncoder(const char *filename) {
  vector<shared_ptr<HTNode>> tree_nodes;
  alphabet_length = 1;
  ifstream fin(filename);
  vector<float> symbol_popularity(256, 0.0f);
  char c;
  while (fin.get(c)) {
    symbol_popularity[(unsigned char) c] += 1.0f;
  }
  for (int i=0; i<256; i++) {
    const auto freq = symbol_popularity[i];
    if (freq > 0.0f) {
      auto node = make_shared<HTNode>(string(1, i), freq, nullptr, nullptr);
      tree_nodes.push_back(node);
    }
  }
  finishConstructing(tree_nodes);
  return;
}
HuffmanEncoder :: HuffmanEncoder ( const char * filename ) { vector < shared_ptr < HTNode > > tree_nodes ; alphabet_length = 1 ; ifstream fin ( filename ) ; vector < float > symbol_popularity ( 256 , 0.0f ) ; char c ; while ( fin . get ( c ) ) { symbol_popularity [ ( unsigned char ) c ] += 1.0f ; } for ( int i = 0 ; i < 256 ; i ++ ) { const auto freq = symbol_popularity [ i ] ; if ( freq > 0.0f ) { auto node = make_shared < HTNode > ( string ( 1 , i ) , freq , nullptr , nullptr ) ; tree_nodes . push_back ( node ) ; } } finishConstructing ( tree_nodes ) ; return ; }
generate symbol frequencies from the given file.
generate symbol frequencies from the given file .