#include #include "cmd_line_parser/parser.hpp" #include "mm_file/mm_file.hpp" #include "tinyformat/tinyformat.h" cmd_line_parser::parser make_parser(int argc, char** argv) { cmd_line_parser::parser p(argc, argv); p.add("input_idx", "Input filepath of trie index"); return p; } xcdat::flag_type get_flag(std::string_view filepath) { std::ifstream ifs(filepath); XCDAT_THROW_IF(!ifs.good(), "Cannot open the input file"); xcdat::flag_type flag; ifs.read(reinterpret_cast(&flag), sizeof(flag)); return flag; } template int decode(const cmd_line_parser::parser& p) { const auto input_idx = p.get("input_idx"); const mm::file_source fin(input_idx.c_str(), mm::advice::sequential); const auto trie = xcdat::mmap(fin.data()); for (std::uint64_t id; std::cin >> id;) { const auto dec = trie.decode(id); tfm::printfln("%d\t%s", id, dec); } return 0; } int main(int argc, char** argv) { #ifndef NDEBUG tfm::warnfln("The code is running in debug mode."); #endif std::ios::sync_with_stdio(false); auto p = make_parser(argc, argv); if (!p.parse()) { return 1; } const auto input_idx = p.get("input_idx"); const auto flag = get_flag(input_idx); switch (flag) { case 7: return decode(p); case 8: return decode(p); default: break; } p.help(); return 1; }