89 {
+
+
91
+
92
+
93
+
95
-
96 size_t border_index = str.
length() + 1;
+
96 size_t current_char = str.
length();
97
-
98 border_pos[current_char] = border_index;
+
98 size_t border_index = str.
length() + 1;
99
-
100 while (current_char > 0) {
-
101 while (border_index <= str.
length() &&
-
102 str[current_char - 1] != str[border_index - 1]) {
-
103 if (arg[border_index] == 0) {
-
104 arg[border_index] = border_index - current_char;
-
105 }
-
106
-
107 border_index = border_pos[border_index];
-
108 }
-
109
-
110 current_char--;
-
111 border_index--;
-
112 border_pos[current_char] = border_index;
-
113 }
-
114
-
115 size_t largest_border_index = border_pos[0];
+
100 border_pos[current_char] = border_index;
+
101
+
102 while (current_char > 0) {
+
103 while (border_index <= str.
length() &&
+
104 str[current_char - 1] != str[border_index - 1]) {
+
105 if (arg[border_index] == 0) {
+
106 arg[border_index] = border_index - current_char;
+
107 }
+
108
+
109 border_index = border_pos[border_index];
+
110 }
+
111
+
112 current_char--;
+
113 border_index--;
+
114 border_pos[current_char] = border_index;
+
115 }
116
-
117 for (
size_t i = 0; i < str.
size(); i++) {
-
118 if (arg[i] == 0) {
-
119 arg[i] = largest_border_index;
-
120 }
-
121
-
122
-
123 if (i == largest_border_index) {
-
124 largest_border_index = border_pos[largest_border_index];
-
125 }
-
126 }
-
127}
+
117 size_t largest_border_index = border_pos[0];
+
118
+
119 for (
size_t i = 0; i < str.
size(); i++) {
+
120 if (arg[i] == 0) {
+
121 arg[i] = largest_border_index;
+
122 }
+
123
+
124
+
125 if (i == largest_border_index) {
+
126 largest_border_index = border_pos[largest_border_index];
+
127 }
+
128 }
+
129}
151 {
-
152 arg.pat = str;
-
-
-
155}
-
void init_bad_char(const std::string &str, std::vector< size_t > &arg)
A function that preprocess the bad char table.
Definition boyer_moore.cpp:136
-
void init_good_suffix(const std::string &str, std::vector< size_t > &arg)
A function that preprocess the good suffix thable.
Definition boyer_moore.cpp:87
+
153 {
+
154 arg.pat = str;
+
+
+
157}
+
void init_bad_char(const std::string &str, std::vector< size_t > &arg)
A function that preprocess the bad char table.
Definition boyer_moore.cpp:138
+
void init_good_suffix(const std::string &str, std::vector< size_t > &arg)
A function that preprocess the good suffix thable.
Definition boyer_moore.cpp:89
@@ -473,19 +473,19 @@ Here is the call graph for this function:
- Returns
true if pat IS prefix of str.
-
false if pat is NOT a prefix of str.
-
198 {
-
-
200 return false;
-
201 }
-
202
-
203 for (size_t i = 0; i < len; i++) {
-
204 if (str[i] != pat[i]) {
-
205 return false;
-
206 }
-
207 }
-
208
-
209 return true;
-
210}
+
200 {
+
+
202 return false;
+
203 }
+
204
+
205 for (size_t i = 0; i < len; i++) {
+
206 if (str[i] != pat[i]) {
+
207 return false;
+
208 }
+
209 }
+
210
+
211 return true;
+
212}
@@ -513,11 +513,11 @@ Here is the call graph for this function:
Main function.
- Returns
- 0 on exit
-
267 {
-
-
269 return 0;
-
270}
-
static void tests()
Self-test implementations.
Definition boyer_moore.cpp:248
+
269 {
+
+
271 return 0;
+
272}
+
static void tests()
Self-test implementations.
Definition boyer_moore.cpp:250
@@ -550,17 +550,17 @@ Here is the call graph for this function:
- Returns
- void
-
233 {
-
-
-
-
237
-
238 assert(indexes.
size() == 6);
+
235 {
+
+
+
239
-
240 for (const auto& currentIndex : indexes) {
-
241 assert(strings::boyer_moore::is_prefix(text + currentIndex, "pat", 3));
-
242 }
-
243}
+
240 assert(indexes.
size() == 6);
+
241
+
242 for (const auto& currentIndex : indexes) {
+
243 assert(strings::boyer_moore::is_prefix(text + currentIndex, "pat", 3));
+
244 }
+
245}
@@ -604,31 +604,31 @@ Here is the call graph for this function:
- Returns
- Vector of indexes of the occurrences of pattern in text
-
163 {
-
164 size_t index_position = arg.pat.size() - 1;
-
-
166
-
167 while (index_position < str.
length()) {
-
168 size_t index_string = index_position;
-
169 int index_pattern = static_cast<int>(arg.pat.size()) - 1;
-
170
-
171 while (index_pattern >= 0 &&
-
172 str[index_string] == arg.pat[index_pattern]) {
-
173 --index_pattern;
-
174 --index_string;
-
175 }
-
176
-
177 if (index_pattern < 0) {
-
178 index_storage.
push_back(index_position - arg.pat.length() + 1);
-
179 index_position += arg.good_suffix[0];
-
180 } else {
-
181 index_position +=
std::max(arg.bad_char[str[index_string]],
-
182 arg.good_suffix[index_pattern + 1]);
-
183 }
-
184 }
-
185
-
186 return index_storage;
-
187}
+
165 {
+
166 size_t index_position = arg.pat.size() - 1;
+
+
168
+
169 while (index_position < str.
length()) {
+
170 size_t index_string = index_position;
+
171 int index_pattern = static_cast<int>(arg.pat.size()) - 1;
+
172
+
173 while (index_pattern >= 0 &&
+
174 str[index_string] == arg.pat[index_pattern]) {
+
175 --index_pattern;
+
176 --index_string;
+
177 }
+
178
+
179 if (index_pattern < 0) {
+
180 index_storage.
push_back(index_position - arg.pat.length() + 1);
+
181 index_position += arg.good_suffix[0];
+
182 } else {
+
183 index_position +=
std::max(arg.bad_char[str[index_string]],
+
184 arg.good_suffix[index_pattern + 1]);
+
185 }
+
186 }
+
187
+
188 return index_storage;
+
189}
Self-test implementations.
- Returns
- void
-
248 {
-
249 const char* text =
-
250 "When pat Mr. and Mrs. pat Dursley woke up on the dull, gray \
-
251 Tuesday our story starts, \
-
252 there was nothing about pat the cloudy sky outside to pat suggest that\
-
253 strange and \
-
254 mysterious things would pat soon be happening all pat over the \
-
255 country.";
-
256
-
-
-
259
-
260 std::cout <<
"All tests have successfully passed!\n";
-
261}
+
250 {
+
251 const char* text =
+
252 "When pat Mr. and Mrs. pat Dursley woke up on the dull, gray \
+
253 Tuesday our story starts, \
+
254 there was nothing about pat the cloudy sky outside to pat suggest that\
+
255 strange and \
+
256 mysterious things would pat soon be happening all pat over the \
+
257 country.";
+
258
+
+
+
261
+
262 std::cout <<
"All tests have successfully passed!\n";
+
263}
-
void pat_test(const char *text)
A test case in which we search for every appearance of the word 'pat'.
Definition boyer_moore.cpp:233
-
void and_test(const char *text)
A test case in which we search for every appearance of the word 'and'.
Definition boyer_moore.cpp:218
+
void pat_test(const char *text)
A test case in which we search for every appearance of the word 'pat'.
Definition boyer_moore.cpp:235
+
void and_test(const char *text)
A test case in which we search for every appearance of the word 'and'.
Definition boyer_moore.cpp:220
diff --git a/d8/ddf/sieve__of__eratosthenes_8cpp.html b/d8/ddf/sieve__of__eratosthenes_8cpp.html
index 27ea8303a..e098f857f 100644
--- a/d8/ddf/sieve__of__eratosthenes_8cpp.html
+++ b/d8/ddf/sieve__of__eratosthenes_8cpp.html
@@ -157,7 +157,7 @@ Space Complexity : \(O(N)\)
71 return 0;
72}
constexpr uint32_t N
A struct to represent sparse table for min() as their invariant function, for the given array A....
Definition sparse_table.cpp:47
-
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:30
+
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:31
std::vector< bool > sieve(uint32_t N)
Definition sieve_of_eratosthenes.cpp:26
void tests()
Definition sieve_of_eratosthenes.cpp:56
diff --git a/db/d93/check__prime_8cpp.html b/db/d93/check__prime_8cpp.html
index bfc79ccea..b9889f807 100644
--- a/db/d93/check__prime_8cpp.html
+++ b/db/d93/check__prime_8cpp.html
@@ -156,11 +156,11 @@ Functions
Main function.
- Returns
- 0 on exit
-
80 {
-
-
82 return 0;
-
83}
-
static void tests()
Self-test implementations.
Definition check_prime.cpp:61
+
81 {
+
+
83 return 0;
+
84}
+
static void tests()
Self-test implementations.
Definition check_prime.cpp:62
@@ -194,23 +194,23 @@ Here is the call graph for this function:
Self-test implementations.
- Returns
- void
-
61 {
-
-
-
-
-
-
-
-
-
-
-
72
-
-
74}
+
62 {
+
+
+
+
+
+
+
+
+
+
+
73
+
+
75}
-
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:30
+
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:31
diff --git a/dd/d47/namespacemath.html b/dd/d47/namespacemath.html
index eebfe2984..8487a0dfe 100644
--- a/dd/d47/namespacemath.html
+++ b/dd/d47/namespacemath.html
@@ -929,31 +929,31 @@ false if number is not a factorial
false if number is not a prime.
Reduce all possibilities of a number which cannot be prime with the first 3 if, else if conditionals. Example: Since no even number, except 2 can be a prime number and the next prime we find after our checks is 5, we will start the for loop with i = 5. then for each loop we increment i by +6 and check if i or i+2 is a factor of the number; if it's a factor then we will return false. otherwise, true will be returned after the loop terminates at the terminating condition which is i*i <= num
-
30 {
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40 if (num <= 1) {
-
41 return false;
-
42 } else if (num == 2 || num == 3) {
-
43 return true;
-
44 } else if (num % 2 == 0 || num % 3 == 0) {
-
45 return false;
-
46 } else {
-
47 for (int64_t i = 5; i * i <= num; i = i + 6) {
-
48 if (num % i == 0 || num % (i + 2) == 0) {
-
49 return false;
-
50 }
+
31 {
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41 if (num <= 1) {
+
42 return false;
+
43 } else if (num == 2 || num == 3) {
+
44 return true;
+
45 } else if (num % 2 == 0 || num % 3 == 0) {
+
46 return false;
+
47 } else {
+
48 for (int64_t i = 5; i * i <= num; i = i + 6) {
+
49 if (num % i == 0 || num % (i + 2) == 0) {
+
50 return false;
51 }
52 }
-
53 return true;
-
54 }
+
53 }
+
54 return true;
+
55}