forked from soulmachine/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextQuery.h
More file actions
37 lines (34 loc) · 931 Bytes
/
TextQuery.h
File metadata and controls
37 lines (34 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <fstream>
#include <memory>
#include <sstream>
#include <algorithm>
using namespace std;
using line_no = vector<string>::size_type;
class QueryResult;
class TextQuery
{
public:
TextQuery(ifstream &infile);
QueryResult query(const string &word) const;
private:
//定义输入文件的智能指针
shared_ptr<vector<string>> file;
//每个单词到它所在行号的集合的映射
map<string, shared_ptr<set<line_no>>> wm;
};
class QueryResult
{
private:
string sought; //查询的单词
shared_ptr<vector<string>> file; //指向查询文件的指针
shared_ptr<set<line_no>> lines; //指向行号的指针
public:
QueryResult(string s, shared_ptr<vector<string>> p, shared_ptr<set<line_no>> l):sought(s), file(p), lines(l){}
QueryResult(const QueryResult& s);
friend ostream& print(ostream&, const QueryResult&);
};