- //steady_clock::time_point start = steady_clock::now();
-
- vector<string> files;
- read_mlocate(infile, &files);
- if (false) { // To read a plain text file.
- FILE *fp = fopen(infile, "r");
- while (!feof(fp)) {
- char buf[1024];
- if (fgets(buf, 1024, fp) == nullptr || feof(fp)) {
- break;
- }
- string s(buf);
- if (s.back() == '\n') s.pop_back();
- files.push_back(move(s));
- }
- fclose(fp);
- }
- dprintf("Read %zu files from %s\n", files.size(), infile);
-
- unordered_map<uint32_t, string> pl;
- size_t trigrams = 0, longest_posting_list = 0;
- unordered_map<uint32_t, vector<uint32_t>> invindex;
- for (size_t i = 0; i < files.size(); ++i) {
- const string &s = files[i];
- if (s.size() >= 3) {
- for (size_t j = 0; j < s.size() - 2; ++j) {
- uint32_t trgm = read_trigram(s, j);
- invindex[trgm].push_back(i);
- }
- }