add flags
This commit is contained in:
parent
78e362de96
commit
49419bf6fc
|
@ -13,18 +13,26 @@ namespace xcdat {
|
|||
using trie_7_type = trie<bc_vector_7>;
|
||||
using trie_8_type = trie<bc_vector_8>;
|
||||
|
||||
using flag_type = std::remove_const_t<decltype(trie_7_type::l1_bits)>;
|
||||
|
||||
template <class Trie>
|
||||
[[maybe_unused]] Trie mmap(const char* address) {
|
||||
Trie idx;
|
||||
mmap_visitor visitor(address);
|
||||
flag_type flag;
|
||||
visitor.visit(flag);
|
||||
XCDAT_THROW_IF(flag != Trie::l1_bits, "The input index type is different.");
|
||||
Trie idx;
|
||||
visitor.visit(idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
[[maybe_unused]] Trie load(std::string_view filepath) {
|
||||
Trie idx;
|
||||
load_visitor visitor(filepath);
|
||||
flag_type flag;
|
||||
visitor.visit(flag);
|
||||
XCDAT_THROW_IF(flag != Trie::l1_bits, "The input index type is different.");
|
||||
Trie idx;
|
||||
visitor.visit(idx);
|
||||
return idx;
|
||||
}
|
||||
|
@ -32,6 +40,7 @@ template <class Trie>
|
|||
template <class Trie>
|
||||
[[maybe_unused]] std::uint64_t save(const Trie& idx, std::string_view filepath) {
|
||||
save_visitor visitor(filepath);
|
||||
visitor.visit(Trie::l1_bits); // flag
|
||||
visitor.visit(const_cast<Trie&>(idx));
|
||||
return visitor.bytes();
|
||||
}
|
||||
|
@ -39,6 +48,7 @@ template <class Trie>
|
|||
template <class Trie>
|
||||
[[maybe_unused]] std::uint64_t memory_in_bytes(const Trie& idx) {
|
||||
size_visitor visitor;
|
||||
visitor.visit(Trie::l1_bits); // flag
|
||||
visitor.visit(const_cast<Trie&>(idx));
|
||||
return visitor.bytes();
|
||||
}
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
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");
|
||||
p.add("trie_type", "Trie type: [7|8] (default=7)", "-t", false);
|
||||
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<char*>(&flag), sizeof(flag));
|
||||
return flag;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
int decode(const cmd_line_parser::parser& p) {
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
|
@ -37,9 +44,10 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
const auto trie_type = p.get<int>("trie_type", 7);
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
const auto flag = get_flag(input_idx);
|
||||
|
||||
switch (trie_type) {
|
||||
switch (flag) {
|
||||
case 7:
|
||||
return decode<xcdat::trie_7_type>(p);
|
||||
case 8:
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
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");
|
||||
p.add("trie_type", "Trie type: [7|8] (default=7)", "-t", false);
|
||||
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<char*>(&flag), sizeof(flag));
|
||||
return flag;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
int enumerate(const cmd_line_parser::parser& p) {
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
|
@ -34,9 +41,10 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
const auto trie_type = p.get<int>("trie_type", 7);
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
const auto flag = get_flag(input_idx);
|
||||
|
||||
switch (trie_type) {
|
||||
switch (flag) {
|
||||
case 7:
|
||||
return enumerate<xcdat::trie_7_type>(p);
|
||||
case 8:
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
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");
|
||||
p.add("trie_type", "Trie type: [7|8] (default=7)", "-t", false);
|
||||
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<char*>(&flag), sizeof(flag));
|
||||
return flag;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
int lookup(const cmd_line_parser::parser& p) {
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
|
@ -41,9 +48,10 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
const auto trie_type = p.get<int>("trie_type", 7);
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
const auto flag = get_flag(input_idx);
|
||||
|
||||
switch (trie_type) {
|
||||
switch (flag) {
|
||||
case 7:
|
||||
return lookup<xcdat::trie_7_type>(p);
|
||||
case 8:
|
||||
|
|
|
@ -8,10 +8,17 @@ 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");
|
||||
p.add("max_num_results", "The max number of results (default=10)", "-n", false);
|
||||
p.add("trie_type", "Trie type: [7|8] (default=7)", "-t", false);
|
||||
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<char*>(&flag), sizeof(flag));
|
||||
return flag;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
int predictive_search(const cmd_line_parser::parser& p) {
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
|
@ -56,9 +63,10 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
const auto trie_type = p.get<int>("trie_type", 7);
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
const auto flag = get_flag(input_idx);
|
||||
|
||||
switch (trie_type) {
|
||||
switch (flag) {
|
||||
case 7:
|
||||
return predictive_search<xcdat::trie_7_type>(p);
|
||||
case 8:
|
||||
|
|
|
@ -7,10 +7,17 @@
|
|||
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");
|
||||
p.add("trie_type", "Trie type: [7|8] (default=7)", "-t", false);
|
||||
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<char*>(&flag), sizeof(flag));
|
||||
return flag;
|
||||
}
|
||||
|
||||
template <class Trie>
|
||||
int prefix_search(const cmd_line_parser::parser& p) {
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
|
@ -54,9 +61,10 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
const auto trie_type = p.get<int>("trie_type", 7);
|
||||
const auto input_idx = p.get<std::string>("input_idx");
|
||||
const auto flag = get_flag(input_idx);
|
||||
|
||||
switch (trie_type) {
|
||||
switch (flag) {
|
||||
case 7:
|
||||
return prefix_search<xcdat::trie_7_type>(p);
|
||||
case 8:
|
||||
|
|
Loading…
Reference in a new issue