Use a flat_map for the thesaurus index

This commit is contained in:
Thomas Goyne 2013-12-20 09:18:24 -08:00
parent d9a2669389
commit 6a193f280e
2 changed files with 5 additions and 5 deletions

View File

@ -35,7 +35,7 @@ namespace agi {
Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path)
: dat(io::Open(dat_path))
{
std::unique_ptr<std::ifstream> idx(io::Open(idx_path));
auto idx = io::Open(idx_path);
std::string encoding_name;
getline(*idx, encoding_name);
@ -43,9 +43,9 @@ Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_pat
getline(*idx, unused_entry_count);
// Read the list of words and file offsets for those words
for (line_iterator<std::string> iter(*idx, encoding_name), end; iter != end; ++iter) {
for (auto const& line : line_iterator<std::string>(*idx, encoding_name)) {
std::vector<std::string> chunks;
boost::split(chunks, *iter, _1 == '|');
boost::split(chunks, line, _1 == '|');
if (chunks.size() == 2)
offsets[chunks[0]] = atoi(chunks[1].c_str());
}

View File

@ -18,8 +18,8 @@
#include "fs_fwd.h"
#include <boost/container/flat_map.hpp>
#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <vector>
@ -30,7 +30,7 @@ namespace charset { class IconvWrapper; }
class Thesaurus {
/// Map of word -> byte position in the data file
std::map<std::string, int> offsets;
boost::container::flat_map<std::string, int> offsets;
/// Read handle to the data file
std::unique_ptr<std::istream> dat;
/// Converter from the data file's charset to UTF-8