Skip to content

Commit 9ddea81

Browse files
committed
Add appropiate qualifiers
1 parent 2dd4710 commit 9ddea81

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

boyer_moore_horspool.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Compile Time Evaluated Boyer Moore Horspool String Search Algorithm
2+
// Author: David Kanekanian
3+
//
4+
// Requires C++17.
5+
16
#include <string_view> // std::string_view
27
#include <optional> // std::optional
38
#include <array> // std::array
@@ -19,7 +24,6 @@ struct SearchPattern {
1924
bad_char_table[i] = needle.length();
2025
}
2126

22-
2327
// Rule 2
2428
// Characters in the needle except last character jump:
2529
// length of needle - last position of character - 1
@@ -30,7 +34,9 @@ struct SearchPattern {
3034
};
3135

3236
/** Returns index of first occurrance of pattern in haystack. */
33-
constexpr std::optional<std::size_t> boyer_moore_horspool(SearchPattern pattern, std::string_view haystack) {
37+
[[nodiscard]] constexpr std::optional<std::size_t> boyer_moore_horspool (
38+
const SearchPattern& pattern,
39+
const std::string_view haystack) noexcept {
3440
for (std::size_t h = 0; h < haystack.length() - pattern.needle.length() + 1;) {
3541
// Search this placement of the needle.
3642
bool found = true;
@@ -63,8 +69,8 @@ int main() {
6369
static_assert(index == 3, "index is supposed to be 3!");
6470

6571
if (index) {
66-
std::cout << "found at index " << index.value() << '\n' << std::flush;
72+
std::cout << "found at index " << index.value() << '\n';
6773
} else {
68-
std::cout << "not found" << std::endl;
74+
std::cout << "not found" << '\n';
6975
}
7076
}

0 commit comments

Comments
 (0)