-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwith_cache.cpp
More file actions
49 lines (40 loc) · 1.03 KB
/
with_cache.cpp
File metadata and controls
49 lines (40 loc) · 1.03 KB
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
41
42
43
44
45
46
47
48
49
#include <vector>
#include <fstream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "analyzer/word_infos.hpp"
#include "analyzer/analyzer.hpp"
int main()
{
Analyzer * analyzer = analyzer_new("dics");
WordInfos * wi = infos_new(1024);
std::map <std::string, bool> cache;
std::vector <std::string> text;
std::vector <int> sizes;
std::ifstream input("input");
std::string str;
// Reading all file to the memory.
while(input >> str)
{
sizes.push_back(str.size());
text.push_back(str);
}
char buffer[1024];
int len = text.size();
for(int i = 0; i < len; i++)
{
std::map <std::string, bool> :: iterator iter = cache.find(text[i]);
if(iter != cache.end())
{
strcpy(&buffer[0], text[i].c_str());
analyzer_get_word_info(analyzer, &buffer[0], sizes[i], wi);
infos_erase(wi);
cache[text[i]] = true;
}
}
infos_free(wi);
analyzer_free(analyzer);
return 0;
}