ronantakizawa/codereview-bench huggingface dataset:
Repository: TheAlgorithms/C-Plus-Plus
File: sorting/stooge_sort.cpp (C++)

Code before:
		if ((*L)[i] > (*L)[j]) {	
			std::swap((*L)[i], (*L)[j]);
		}
		if (j - i > 1) {
			int third = (j - i + 1) / 3;
			stoogeSort(L, i, j - third);
			stoogeSort(L, i + third, j);
			stoogeSort(L, i, j - third);
		}
	}
	return;
}

/**
 * @brief Function to test sorting algorithm
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element
 */
void test2() {
	std::vector<int> L = { -1};
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5};
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
	test1();
	test2();
	test3();
	return 0;

Review comment (suggestion):
```suggestion
 * @brief Function to test sorting algorithm, one element
 * @returns void
```


Code after:
    if (i >= j) {
        return;
    }
    if ((*L)[i] > (*L)[j]) {
        std::swap((*L)[i], (*L)[j]);
    }
    if (j - i > 1) {
        size_t third = (j - i + 1) / 3;
        stoogeSort(L, i, j - third);
        stoogeSort(L, i + third, j);
        stoogeSort(L, i, j - third);
    }
}

/**
 * @brief Function to test sorting algorithm
 * @returns void
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element
 * @returns void
 */
void test2() {
	std::vector<int> L = { -1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 * @returns void
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
Repository: TheAlgorithms/C-Plus-Plus
File: sorting/stooge_sort.cpp (C++)

Code before:
	return;
}

/**
 * @brief Function to test sorting algorithm
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element
 */
void test2() {
	std::vector<int> L = { -1};
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5};
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
	test1();
	test2();
	test3();
	return 0;
}


Review comment (suggestion):
```suggestion
 * @brief Function to test sorting algorithm, repeating elements
 * @returns void
```


Code after:
        stoogeSort(L, i, j - third);
    }
}

/**
 * @brief Function to test sorting algorithm
 * @returns void
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element
 * @returns void
 */
void test2() {
	std::vector<int> L = { -1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 * @returns void
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
	test1();
	test2();
	test3();
    
    std::cout << "All tests have successfully passed!\n";
	return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: sorting/stooge_sort.cpp (C++)

Code before:
/**
 * @file
 * @brief [Stooge sort implementation](https://en.wikipedia.org/wiki/Stooge_sort)
 * in C++
 * @details
 * Stooge sort is a recursive sorting algorithm.
 * It divides the array into 3 parts and proceeds to:
 *	- sort first two thirds of the array
 *	- sort last two thirds of the array
 *  - sort first two thirds of the array
 * It's time complexity is O(n^(log3/log1.5)), which is about O(n^2.7),
 * which makes it to be not the most efficient sorting algorithm
 * on the street on average. Space complexity is O(1).
 */

#include <vector> /// for vector
#include <cassert> /// for assert
#include <algorithm>  /// for std::is_sorted

 /**
  * @brief The stoogeSort() function is used for sorting the array.
  * @param L - vector of values (int) to be sorted in in place (ascending order)
  * @param i - the first index of the array (0)
  * @param j - the last index of the array (L.size() - 1)
  * @returns void
  */
void stoogeSort(std::vector<int>* L, size_t i, size_t j) {
	if (i < j) {
		if ((*L)[i] > (*L)[j]) {
			std::swap((*L)[i], (*L)[j]);
		}
		if (j - i > 1) {
			size_t third = (j - i + 1) / 3;
			stoogeSort(L, i, j - third);
			stoogeSort(L, i + third, j);
			stoogeSort(L, i, j - third);
		}
	}
	return;
}

/**
 * @brief Function to test sorting algorithm

Review comment (suggestion):
```suggestion
#include <vector>     /// for vector
#include <cassert>    /// for assert
#include <algorithm>  /// for std::is_sorted
#include <iostream>   /// for IO operations
```


Code after:
/**
 * @file
 * @brief [Stooge sort implementation](https://en.wikipedia.org/wiki/Stooge_sort)
 * in C++
 * @details
 * Stooge sort is a recursive sorting algorithm.
 * It divides the array into 3 parts and proceeds to:
 *	- sort first two thirds of the array
 *	- sort last two thirds of the array
 *  - sort first two thirds of the array
 * It's time complexity is O(n^(log3/log1.5)), which is about O(n^2.7),
 * which makes it to be not the most efficient sorting algorithm
 * on the street on average. Space complexity is O(1).
 */

#include <vector> /// for vector
#include <cassert> /// for assert
#include <algorithm>  /// for std::is_sorted
#include <iostream>   /// for IO operations

 /**
  * @brief The stoogeSort() function is used for sorting the array.
  * @param L - vector of values (int) to be sorted in in place (ascending order)
  * @param i - the first index of the array (0)
  * @param j - the last index of the array (L.size() - 1)
  * @returns void
  */
void stoogeSort(std::vector<int>* L, size_t i, size_t j) {
    if (i >= j) {
        return;
    }
    if ((*L)[i] > (*L)[j]) {
        std::swap((*L)[i], (*L)[j]);
    }
    if (j - i > 1) {
        size_t third = (j - i + 1) / 3;
        stoogeSort(L, i, j - third);
        stoogeSort(L, i + third, j);
        stoogeSort(L, i, j - third);
    }
}

/**
Repository: TheAlgorithms/C-Plus-Plus
File: sorting/stooge_sort.cpp (C++)

Code before:
	std::vector<int> L = { -1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 * @returns void
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
	test1();
	test2();
	test3();
	return 0;
}


Review comment (suggestion):
With no printing message, the user might be confused on what the program's doing or did.
```suggestion
	test3();

	std::cout << "All tests have successfully passed!\n";
```


Code after:
void test2() {
	std::vector<int> L = { -1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, repeating elements
 * @returns void
 */
void test3() {
	std::vector<int> L = { 1, 2, 5, 4, 1, 5 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Main function
 * @param argc commandline argument count (ignored)
 * @param argv commandline array of arguments (ignored)
 * @returns 0 on exit
 */
int main() {
	test1();
	test2();
	test3();
    
    std::cout << "All tests have successfully passed!\n";
	return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: sorting/stooge_sort.cpp (C++)

Code before:
 * in C++
 * @details
 * Stooge sort is a recursive sorting algorithm.
 * It divides the array into 3 parts and proceeds to:
 *	- sort first two thirds of the array
 *	- sort last two thirds of the array
 *  - sort first two thirds of the array
 * It's time complexity is O(n^(log3/log1.5)), which is about O(n^2.7),
 * which makes it to be not the most efficient sorting algorithm
 * on the street on average. Space complexity is O(1).
 */

#include <vector> /// for vector
#include <cassert> /// for assert
#include <algorithm>  /// for std::is_sorted
#include <iostream>   /// for IO operations

 /**
  * @brief The stoogeSort() function is used for sorting the array.
  * @param L - vector of values (int) to be sorted in in place (ascending order)
  * @param i - the first index of the array (0)
  * @param j - the last index of the array (L.size() - 1)
  * @returns void
  */
void stoogeSort(std::vector<int>* L, size_t i, size_t j) {
	if (i < j) {
		if ((*L)[i] > (*L)[j]) {
			std::swap((*L)[i], (*L)[j]);
		}
		if (j - i > 1) {
			size_t third = (j - i + 1) / 3;
			stoogeSort(L, i, j - third);
			stoogeSort(L, i + third, j);
			stoogeSort(L, i, j - third);
		}
	}
	return;
}

/**
 * @brief Function to test sorting algorithm
 * @returns void
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element

Review comment (suggestion):
What if to reverse:
```cpp
if (i >= j){
    return;
}
```

Code after:
 * in C++
 * @details
 * Stooge sort is a recursive sorting algorithm.
 * It divides the array into 3 parts and proceeds to:
 *	- sort first two thirds of the array
 *	- sort last two thirds of the array
 *  - sort first two thirds of the array
 * It's time complexity is O(n^(log3/log1.5)), which is about O(n^2.7),
 * which makes it to be not the most efficient sorting algorithm
 * on the street on average. Space complexity is O(1).
 */

#include <vector> /// for vector
#include <cassert> /// for assert
#include <algorithm>  /// for std::is_sorted
#include <iostream>   /// for IO operations

 /**
  * @brief The stoogeSort() function is used for sorting the array.
  * @param L - vector of values (int) to be sorted in in place (ascending order)
  * @param i - the first index of the array (0)
  * @param j - the last index of the array (L.size() - 1)
  * @returns void
  */
void stoogeSort(std::vector<int>* L, size_t i, size_t j) {
    if (i >= j) {
        return;
    }
    if ((*L)[i] > (*L)[j]) {
        std::swap((*L)[i], (*L)[j]);
    }
    if (j - i > 1) {
        size_t third = (j - i + 1) / 3;
        stoogeSort(L, i, j - third);
        stoogeSort(L, i + third, j);
        stoogeSort(L, i, j - third);
    }
}

/**
 * @brief Function to test sorting algorithm
 * @returns void
 */
void test1() {
	std::vector<int> L = { 8, 9, 10, 4, 3, 5, 1 };
	stoogeSort(&L, 0, L.size() - 1);
	assert(std::is_sorted(std::begin(L), std::end(L)));
}

/**
 * @brief Function to test sorting algorithm, one element
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;

Review comment (suggestion):
Please add a one-line description of what the library/header is for (**see the example below**).

```c++
#include <iostream>    /// for IO operations
#include <cassert>    /// for assert
```


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)
Repository: TheAlgorithms/C-Plus-Plus
File: strings/boyer_moore.cpp (C++)

Code before:
    return true;
}

void and_test(const char* text) {
    pattern ands;
    init_pattern("and", ands);
    std::vector<size_t> indexes = search(text, ands);

    assert(indexes.size() == 2);
    assert(is_prefix(text + indexes[0], "and", 3));
    assert(is_prefix(text + indexes[1], "and", 3));
}

void pat_test(const char* text) {
    pattern pat;
    init_pattern("pat", pat);
    std::vector<size_t> indexes = search(text, pat);

    assert(indexes.size() == 6);

    for (const auto& idx : indexes) {
        assert(is_prefix(text + idx, "pat", 3));
    }
}

void tests() {
    const char* text =
        "When pat Mr. and Mrs. pat Dursley woke up on the dull, gray  \
                            Tuesday our story starts, \
                there was nothing about pat the cloudy sky outside to pat suggest that\
                        strange and \
                    mysterious things would pat soon be happening all pat over the \
                        country.";

    and_test(text);
    pat_test(text);
}

int main() { tests(); }


Review comment (suggestion):
```suggestion
/**
 * @brief Self-test implementations
 * @returns void
 */
static void tests() {
```


Code after:

/**
 * @brief A function that preprocess the bad char table
 *
 * @param str The string being preprocessed
 * @param arg The bad char table
 * @returns void
 */
void init_bad_char(const std::string& str, std::vector<size_t>& arg) {
    arg.resize(APLHABET_SIZE, str.length());

    for (size_t i = 0; i < str.length(); i++) {
        arg[str[i]] = str.length() - i - 1;
    }
}

/**
 * @brief A function that initializes pattern
 *
 * @param str Text used for initialization
 * @param arg Initialized structure
 * @returns void
 */
void init_pattern(const std::string& str, pattern& arg) {
    arg.pat = str;
    init_bad_char(str, arg.bad_char);
    init_good_suffix(str, arg.good_suffix);
}
/**
 * @brief A function that implements Boyer-Moore's algorithm.
 *
 * @param str Text we are seatching in.
 * @param arg pattern structure containing the preprocessed pattern
 * @return Vector of indexes of the occurrences of pattern in text
 */
std::vector<size_t> search(const std::string& str, const pattern& arg) {
    size_t index_position = arg.pat.size() - 1;
    std::vector<size_t> index_storage;

    while (index_position < str.length()) {
        size_t index_string = index_position;
        int index_pattern = static_cast<int>(arg.pat.size()) - 1;

        while (index_pattern >= 0 &&
               str[index_string] == arg.pat[index_pattern]) {
            --index_pattern;
            --index_string;
        }

        if (index_pattern < 0) {
            index_storage.push_back(index_position - arg.pat.length() + 1);
Repository: TheAlgorithms/C-Plus-Plus
File: strings/boyer_moore.cpp (C++)

Code before:
void pat_test(const char* text) {
    pattern pat;
    init_pattern("pat", pat);
    std::vector<size_t> indexes = search(text, pat);

    assert(indexes.size() == 6);

    for (const auto& idx : indexes) {
        assert(is_prefix(text + idx, "pat", 3));
    }
}

void tests() {
    const char* text =
        "When pat Mr. and Mrs. pat Dursley woke up on the dull, gray  \
                            Tuesday our story starts, \
                there was nothing about pat the cloudy sky outside to pat suggest that\
                        strange and \
                    mysterious things would pat soon be happening all pat over the \
                        country.";

    and_test(text);
    pat_test(text);
}

int main() { tests(); }


Review comment (suggestion):
```suggestion
/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    tests();
    return 0;
}
```


Code after:
    }
}

/**
 * @brief A function that initializes pattern
 *
 * @param str Text used for initialization
 * @param arg Initialized structure
 * @returns void
 */
void init_pattern(const std::string& str, pattern& arg) {
    arg.pat = str;
    init_bad_char(str, arg.bad_char);
    init_good_suffix(str, arg.good_suffix);
}
/**
 * @brief A function that implements Boyer-Moore's algorithm.
 *
 * @param str Text we are seatching in.
 * @param arg pattern structure containing the preprocessed pattern
 * @return Vector of indexes of the occurrences of pattern in text
 */
std::vector<size_t> search(const std::string& str, const pattern& arg) {
    size_t index_position = arg.pat.size() - 1;
    std::vector<size_t> index_storage;

    while (index_position < str.length()) {
        size_t index_string = index_position;
        int index_pattern = static_cast<int>(arg.pat.size()) - 1;

        while (index_pattern >= 0 &&
               str[index_string] == arg.pat[index_pattern]) {
            --index_pattern;
            --index_string;
        }

        if (index_pattern < 0) {
            index_storage.push_back(index_position - arg.pat.length() + 1);
            index_position += arg.good_suffix[0];
        } else {
            index_position += std::max(arg.bad_char[str[index_string]],
                                       arg.good_suffix[index_pattern + 1]);
        }
    }

    return index_storage;
}

/**
 * @brief Check if pat is prefix of str.
 *
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> /// for assert
#include <cstring> /// for strlen
#include <limits>  /// for CHAR_MAX macro
#include<string>   /// for std::string
#include <vector>  /// for std::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
 * @return void
 */
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);

Review comment (suggestion):
Please add documentation for this variable.
```suggestion
#define APLHABET_SIZE CHAR_MAX   ///< <description here>
```


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