// Paso 6, con trie: cuántos nodos ocupa, según las claves. Uso: trie_sizes archivo...
// Lee un .tsv como calles (nodo, nombre) y cualquier otro archivo como una palabra por línea.
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>

#include "trie.h"

int main(int argc, char* argv[]) {
    std::cout << "    claves   bytes de claves      nodos  nodos/byte  con 256 hijos, MB\n";
    for (int i = 1; i < argc; i++) {
        PlaceTrie trie;
        std::size_t bytes = 0;
        std::ifstream file(argv[i]);
        std::string line;
        int id = 0;
        while (std::getline(file, line)) {
            std::size_t tab = line.find('\t');
            std::string name = tab == std::string::npos ? line : line.substr(tab + 1);
            bytes += name.size();
            trie.insert(name, id++);
        }
        std::cout << std::setw(10) << trie.place_count() << std::setw(18) << bytes << std::setw(11) << trie.node_count()
                  << std::fixed << std::setprecision(2) << std::setw(12)
                  << static_cast<double>(trie.node_count()) / static_cast<double>(bytes) << std::setw(19)
                  << static_cast<double>(trie.node_count()) * 256 * sizeof(int) / 1e6 << "\n";
    }
    return 0;
}
