-
Notifications
You must be signed in to change notification settings - Fork 0
/
general.cpp
83 lines (71 loc) · 1.76 KB
/
general.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "general.hpp"
namespace general
{
void readWordFile(
const std::string& file_path
, char* word_array
, size_t num
, size_t offset)
{
std::string input_word;
std::ifstream word_file(file_path);
if (word_file.is_open()) {
for (size_t i{}; i < offset; ++i)
word_file >> input_word;
for (size_t i{}; i < num && word_file; ++i) {
word_file >> input_word;
if (input_word.length() < word_size)
strcpy(&word_array[i * word_size], input_word.c_str());
}
}
}
std::chrono::milliseconds preprocessData(
char* data, const size_t data_length)
{
auto start{ std::chrono::system_clock::now() };
for (size_t i{ 0 }; i < data_length; ++i) {
static size_t wdidx;
wdidx = i * word_size;
static size_t j;
static char c;
for (j = 0; j < word_size; ++j) {
c = data[wdidx + j];
c = tolower(c);
if (c <= 'z' && c >= 'a') {
while (c <= 'z' && c >= 'a') {
data[wdidx] = c;
++wdidx;
c = data[wdidx + j];
c = tolower(c);
}
data[wdidx] = '\0';
break;
}
}
}
auto end{ std::chrono::system_clock::now() };
auto millis{ std::chrono::duration_cast<std::chrono::milliseconds>(end - start) };
return millis;
}
std::chrono::milliseconds processData(
const char* data
, const size_t data_length
, const char* keywords
, int* histogram)
{
auto start{ std::chrono::system_clock::now() };
for (int i{ 0 }; i < data_length; ++i) {
static int j;
j = 0;
for (; j < keywords_length; ++j) {
if (strcmp(&data[i * word_size], &keywords[j * word_size]) == 0) {
++histogram[j];
break;
}
}
}
auto end{ std::chrono::system_clock::now() };
auto millis{ std::chrono::duration_cast<std::chrono::milliseconds>(end - start) };
return millis;
}
}