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

Code before:
/**
 * @file
 * @brief
 * The Boyer–Moore 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.
 *

Review comment (suggestion):
```suggestion
 * 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
```


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

Code before:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree)
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     // For IO operations
#include <vector>       // For std::vector
#include <algorithm>    // For std::min and std::max
#include <cassert>      // For assert

/*
 * @namespace data_structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @param n The size of the tree
 * @tparam T The type of the class that goes in the datastructure
 */

Review comment (suggestion):
```suggestion
 * @brief A data structure to quickly do operations on ranges: the [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree) algorithm implementation
```


Code after:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: the [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree) algorithm implementation
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     /// For IO operations
#include <vector>       /// For std::vector
#include <algorithm>    /// For std::min and std::max
#include <cassert>      /// For assert

/*
 * @namespace
 * @brief Data structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @tparam T The type of the class that goes in the datastructure
 */
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree)
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     // For IO operations
#include <vector>       // For std::vector
#include <algorithm>    // For std::min and std::max
#include <cassert>      // For assert

/*
 * @namespace data_structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @param n The size of the tree
 * @tparam T The type of the class that goes in the datastructure
 */
template <class T>
class SegmentTree {
private:
    const T ID = 0;   ///< Comb(ID, x) = x
    std::vector<T> t; ///< Vector to represent the tree
    int size;
private:
    /**
     * @brief Any associative function that combines x and y
     * @param x The first operand
     * @param y The second operand
     * @return Some associative operation applied to these two values. In this case, I used addition
     */
    T comb(T x, T y) {
        return x + y;

Review comment (suggestion):
```suggestion
#include <iostream>     /// For IO operations
#include <vector>       /// For std::vector
#include <algorithm>    /// For std::min and std::max
#include <cassert>      /// For assert
```


Code after:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: the [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree) algorithm implementation
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     /// For IO operations
#include <vector>       /// For std::vector
#include <algorithm>    /// For std::min and std::max
#include <cassert>      /// For assert

/*
 * @namespace
 * @brief Data structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @tparam T The type of the class that goes in the datastructure
 */
template <class T>
class SegmentTree {
private:
    const T ID = 0;   ///< Comb(ID, x) = x
    std::vector<T> t; ///< Vector to represent the tree
    int size = 0;     ///< Number of elements available for querying in the tree
private:
    /**
     * @brief Any associative function that combines x and y
     * @param x The first operand
     * @param y The second operand
     * @return Some associative operation applied to these two values. In this case, I used addition
     */
    T comb(T x, T y) {
        return x + y;
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree)
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     // For IO operations
#include <vector>       // For std::vector
#include <algorithm>    // For std::min and std::max
#include <cassert>      // For assert

/*
 * @namespace data_structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @param n The size of the tree
 * @tparam T The type of the class that goes in the datastructure
 */
template <class T>
class SegmentTree {
private:
    const T ID = 0;   ///< Comb(ID, x) = x
    std::vector<T> t; ///< Vector to represent the tree
    int size;
private:
    /**
     * @brief Any associative function that combines x and y
     * @param x The first operand
     * @param y The second operand
     * @return Some associative operation applied to these two values. In this case, I used addition
     */
    T comb(T x, T y) {
        return x + y;
    }
    /**
     * @brief Gives the midpoint between two integers

Review comment (suggestion):
```suggestion
 * @namespace
 * @brief Data structures
```


Code after:
/**
 * @file
 * @brief A data structure to quickly do operations on ranges: the [Segment Tree](https://en.wikipedia.org/wiki/Segment_tree) algorithm implementation
 * @details
 * Implementation of the segment tree data structre
 *
 * Can do point updates (updates the value of some position)
 * and range queries, where it gives the value of some associative
 * opperation done on a range
 *
 * Both of these operations take O(log N) time
 * @author [Nishant Chatterjee](https://github.com/nishantc1527)
 */

#include <iostream>     /// For IO operations
#include <vector>       /// For std::vector
#include <algorithm>    /// For std::min and std::max
#include <cassert>      /// For assert

/*
 * @namespace
 * @brief Data structures
 */
namespace data_structures {
/**
 * @brief class representation of the segment tree
 * @tparam T The type of the class that goes in the datastructure
 */
template <class T>
class SegmentTree {
private:
    const T ID = 0;   ///< Comb(ID, x) = x
    std::vector<T> t; ///< Vector to represent the tree
    int size = 0;     ///< Number of elements available for querying in the tree
private:
    /**
     * @brief Any associative function that combines x and y
     * @param x The first operand
     * @param y The second operand
     * @return Some associative operation applied to these two values. In this case, I used addition
     */
    T comb(T x, T y) {
        return x + y;
    }
    /**
     * @brief Gives the midpoint between two integers
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief self test implementations
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8
}

/**
 * @brief Main function
 */
int main() {
    test();
}


Review comment (suggestion):
```suggestion
 * @brief Main function
 * @returns 0 on exit
```


Code after:
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief self test implementations
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8
}

/**
 * @brief Main function
 */
int main() {
    test();
}


Review comment (suggestion):
```suggestion
    test();  // run self-test implementations
    return 0;
```


Code after:
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
        return comb(range_comb(i * 2, l, m, tl, std::min(tr, m)), range_comb(i * 2 + 1, m + 1, r, std::max(tl, m + 1), tr));
    }
public:
    SegmentTree(int n) : t(n * 4, ID), size(n) {}
    /** 
     * @brief Updates a value at a certain position
     * @param pos The position to update
     * @param val The value to update it to
     */
    void update(int pos, T val) {
        update(1, 1, size, pos, val);
    }
    /**
     * @brief Returns comb across all values between l and r
     * @param l The left endpoint of the range
     * @param r The right endpoint of the range
     * @return The value of the comb operations
     */
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief self test implementations
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8
}

/**
 * @brief Main function
 */
int main() {
    test();
}


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


Code after:
        return comb(range_comb(i * 2, l, m, tl, std::min(tr, m)), range_comb(i * 2 + 1, m + 1, r, std::max(tl, m + 1), tr));
    }
public:
    SegmentTree(int n) : t(n * 4, ID), size(n) {}
    /** 
     * @brief Updates a value at a certain position
     * @param pos The position to update
     * @param val The value to update it to
     */
    void update(int pos, T val) {
        update(1, 1, size, pos, val);
    }
    /**
     * @brief Returns comb across all values between l and r
     * @param l The left endpoint of the range
     * @param r The right endpoint of the range
     * @return The value of the comb operations
     */
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: data_structures/segment_tree.cpp (C++)

Code before:
    /**
     * @brief Returns comb across all values between l and r
     * @param l The left endpoint of the range
     * @param r The right endpoint of the range
     * @return The value of the comb operations
     */
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}


Review comment (suggestion):
```suggestion
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8

    std::cout << "All tests have successfully passed!\n";
```


Code after:
    /**
     * @brief Returns comb across all values between l and r
     * @param l The left endpoint of the range
     * @param r The right endpoint of the range
     * @return The value of the comb operations
     */
    T range_comb(int l, int r) {
        return range_comb(1, 1, size, l, r);
    }
};
} // namespace data_structures

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    data_structures::SegmentTree<int> t(5);
    t.update(1, 1);
    t.update(2, 2);
    t.update(3, 3);
    t.update(4, 4);
    t.update(5, 5);
    assert(t.range_comb(1, 3) == 6); // 1 + 2 + 3 = 6
    t.update(1, 3);
    assert(t.range_comb(1, 3) == 8); // 3 + 2 + 3 = 8

    std::cout << "All tests have successfully passed!\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: backtracking/generate_parentheses.cpp (C++)

Code before:
/**
 * @file
 * @brief Generates all combinations of well-formed parentheses.
 *
 * @details a sequence of parentheses is well-formed if each opening parentheses
 has a corresponding closing parenthesis
 *  and the closing parentheses are correctly ordered
 *
 * @author [Giuseppe Coco](https://github.com/WoWS17)

 */

#include <cassert>
#include <iostream>
#include <vector>

class generate_parentheses {
 private:
    std::vector<std::string> res;  // Contains all possible valid patterns

    /**
     * @brief function that implements backtracking
     *
     * @param str string build during backtracking
     * @param n number of pairs of parentheses
     * @param closed number of closed parentheses
     * @param open number of open parentheses
     */

    void makeStrings(std::string str, int n, int closed, int open) {
        if (closed > open)  // We can never have more closed than open
            return;

        if (str.length() == 2 * n and
            closed != open)  // closed and open must be the same
            return;

        if (str.length() == 2 * n) {
            res.push_back(str);
            return;

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 Well-formed [Generated
 * Parentheses](https://leetcode.com/explore/interview/card/top-interview-questions-medium/109/backtracking/794/) with all combinations.
 *
 * @details a sequence of parentheses is well-formed if each opening parentheses
 * has a corresponding closing parenthesis
 * and the closing parentheses are correctly ordered
 *
 * @author [Giuseppe Coco](https://github.com/WoWS17)

 */

#include <cassert>   /// for assert
#include <iostream>  /// for I/O operation
#include <vector>    /// for vector container

/**
 * @brief Backtracking algorithms
 * @namespace backtracking
 */
namespace backtracking {
/**
 * @brief generate_parentheses class
 */
class generate_parentheses {
 private:
    std::vector<std::string> res;  ///< Contains all possible valid patterns

    void makeStrings(std::string str, int n, int closed, int open);

 public:
    std::vector<std::string> generate(int n);
};

/**
 * @brief function that adds parenthesis to the string.
 *
 * @param str string build during backtracking
 * @param n number of pairs of parentheses