Skip to content

Instantly share code, notes, and snippets.

@JeOam
Created July 14, 2018 09:40
Show Gist options
  • Save JeOam/66b5d4f0c493f7bd7385429f17dcfc9f to your computer and use it in GitHub Desktop.
Save JeOam/66b5d4f0c493f7bd7385429f17dcfc9f to your computer and use it in GitHub Desktop.
C++ 文本查询程序设计(12.3.1)
@JeOam
Copy link
Author

JeOam commented Jul 14, 2018

QueryResult TextQuery::query(const string &sought) const
{
  static shared_ptr<set<line_no>> nodata(new set<line_no>);
  auto loc = wm.find(sought);
  if (loc == wm.end()) 
    return QueryResult(sought, nodata, file)
  else
    return QueryResult(sought, loc->second, file);
}

@JeOam
Copy link
Author

JeOam commented Jul 14, 2018

ostream &print(ostream & os, cosnt QueryResult &qr)
{
  os << qr.sought << " occurs " << qr.lines->size() << " "
     << make_plural(qr.lines->size(), "time", "s") << endl;
  for (auto num: *qr.lines)
    os << "\t(line )" << num + 1 << ") "
       << *(qr.file->begin() + num) << endl;
  return os;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment