Repository: TheAlgorithms/C-Plus-Plus
File: strings/boyer_moore.cpp (C++)

Code before:
/**
 * @file
 * @brief Boyer-moore's algorithm finding all occurrences of pattern in given
 * text.
 * @author [Stoycho Kyosev](https://github.com/stoychoX)
 */
#include <cassert>
#include <cstring>
#include <iostream>
#include <limits>
#include <vector>

#define APLHABET_SIZE CHAR_MAX

/// @brief A structure representing all the data we need to search the
/// preprocessed pattern in text.
struct pattern {
    std::string pat;

    std::vector<size_t> bad_char;
    std::vector<size_t> good_suffix;
};

/// @brief A function that preprocess the good suffix thable
/// @param str The string being preprocessed
/// @param arg The good suffix table
void init_good_suffix(const std::string& str, std::vector<size_t>& arg) {
    arg.resize(str.size() + 1, 0);

    // border_pos[i] - the index of the longest proper suffix of str[i..] which
    // is also a proper prefix.
    std::vector<size_t> border_pos(str.size() + 1, 0);

    int current_char = str.length();

    size_t border_index = str.length() + 1;

    border_pos[current_char] = border_index;

    while (current_char > 0) {
        while (border_index <= str.length() &&

Review comment (suggestion):
Please document the functions/anything else similar to this format.
```suggestion
/**
 * @brief A structure representing all the data we need to search the
 * preprocessed pattern in the text.
```


Code after:
/**
 * @file
 * @brief
 * The [Boyer–Moore](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm) algorithm searches for occurrences of pattern P in text T by
 * performing explicit character comparisons at different alignments. Instead of
 * a brute-force search of all alignments (of which there are n - m + 1),
 * Boyer–Moore uses information gained by preprocessing P to skip as many
 * alignments as possible.
 *
 * @details
 * The key insight in this algorithm is that if the end of the pattern is
 * compared to the text, then jumps along the text can be made rather than
 * checking every character of the text. The reason that this works is that in
 * lining up the pattern against the text, the last character of the pattern is
 * compared to the character in the text.
 *
 * If the characters do not match, there is no need to continue searching
 * backwards along the text. This leaves us with two cases.
 *
 * Case 1:
 * If the character in the text does not match any of the characters in the
 * pattern, then the next character in the text to check is located m characters
 * farther along the text, where m is the length of the pattern.
 *
 * Case 2:
 * If the character in the text is in the pattern, then a partial shift of the
 * pattern along the text is done to line up along the matching character and
 * the process is repeated.
 *
 * There are two shift rules:
 *
 * [The bad character rule]
 * (https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm#The_bad_character_rule)
 *
 * [The good suffix rule]
 * (https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm#The_good_suffix_rule)
 *
 * The shift rules are implemented as constant-time table lookups, using tables
 * generated during the preprocessing of P.
 * @author [Stoycho Kyosev](https://github.com/stoychoX)
 */