enable mmap

This commit is contained in:
Shunsuke Kanda 2021-06-29 10:45:02 +09:00
parent 9a6c598519
commit 8634d7fb60
5 changed files with 18 additions and 5 deletions

View file

@ -1,6 +1,7 @@
#include <xcdat.hpp>
#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) {
@ -13,7 +14,9 @@ cmd_line_parser::parser make_parser(int argc, char** argv) {
template <class Trie>
int decode(const cmd_line_parser::parser& p) {
const auto input_idx = p.get<std::string>("input_idx");
const auto trie = xcdat::load<Trie>(input_idx);
const mm::file_source<char> fin(input_idx.c_str(), mm::advice::sequential);
const auto trie = xcdat::mmap<Trie>(fin.data());
for (std::uint64_t id; std::cin >> id;) {
const auto dec = trie.decode(id);

View file

@ -1,6 +1,7 @@
#include <xcdat.hpp>
#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) {
@ -13,7 +14,9 @@ cmd_line_parser::parser make_parser(int argc, char** argv) {
template <class Trie>
int enumerate(const cmd_line_parser::parser& p) {
const auto input_idx = p.get<std::string>("input_idx");
const auto trie = xcdat::load<Trie>(input_idx);
const mm::file_source<char> fin(input_idx.c_str(), mm::advice::sequential);
const auto trie = xcdat::mmap<Trie>(fin.data());
trie.enumerate([&](std::uint64_t id, std::string_view str) { tfm::printfln("%d\t%s", id, str); });

View file

@ -1,6 +1,7 @@
#include <xcdat.hpp>
#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) {
@ -13,7 +14,9 @@ cmd_line_parser::parser make_parser(int argc, char** argv) {
template <class Trie>
int lookup(const cmd_line_parser::parser& p) {
const auto input_idx = p.get<std::string>("input_idx");
const auto trie = xcdat::load<Trie>(input_idx);
const mm::file_source<char> fin(input_idx.c_str(), mm::advice::sequential);
const auto trie = xcdat::mmap<Trie>(fin.data());
for (std::string str; std::getline(std::cin, str);) {
const auto id = trie.lookup(str);

View file

@ -1,6 +1,7 @@
#include <xcdat.hpp>
#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) {
@ -16,7 +17,8 @@ int predictive_search(const cmd_line_parser::parser& p) {
const auto input_idx = p.get<std::string>("input_idx");
const auto max_num_results = p.get<std::uint64_t>("max_num_results", 10);
const auto trie = xcdat::load<Trie>(input_idx);
const mm::file_source<char> fin(input_idx.c_str(), mm::advice::sequential);
const auto trie = xcdat::mmap<Trie>(fin.data());
struct result_type {
std::uint64_t id;

View file

@ -1,6 +1,7 @@
#include <xcdat.hpp>
#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) {
@ -14,7 +15,8 @@ template <class Trie>
int prefix_search(const cmd_line_parser::parser& p) {
const auto input_idx = p.get<std::string>("input_idx");
const auto trie = xcdat::load<Trie>(input_idx);
const mm::file_source<char> fin(input_idx.c_str(), mm::advice::sequential);
const auto trie = xcdat::mmap<Trie>(fin.data());
struct result_type {
std::uint64_t id;