-
Notifications
You must be signed in to change notification settings - Fork 2
/
History.cpp
40 lines (36 loc) · 875 Bytes
/
History.cpp
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
38
39
40
#include "History.h"
void History::addHistory(const std::wstring &path) {
for (int i = 0; i < his.size(); i++) {
if (his[i] == path) {
num[i]++;
return;
}
}
his.push_back(path);
num.push_back(1);
}
std::wstring identifyName(const std::wstring& path) {
for (int i = path.length() - 1; i > 0; i--) {
if (path[i] == L'\\')
return path.substr(i + 1);
}
return path;
}
std::vector<std::wstring> History::recommend(const std::wstring &path) {
std::vector<std::wstring> result;
std::vector<int> res_num;
std::wstring name = identifyName(path);
for (int i = 0; i < his.size(); i++) {
int loc = his[i].find(name);
if (loc > -1) {
int j = 0;
for (j = 0; j < result.size(); j++) {
if (res_num[j] < num[i])
break;
}
result.insert(result.begin() + j, his[i]);
res_num.insert(res_num.begin() + j, num[i]);
}
}
return result;
}