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

Code before:
 *
 * @param x int to get hash from
 * @return hash for x
 */
std::size_t hashInt_1(int x) {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
}

/**
 * @brief [Hash function for
 * test](https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key)
 *
 * @param x int to get hash from
 * @return hash for x
 */
std::size_t hashInt_2(int x) {
    auto y = static_cast<std::size_t>(x);
    y = (y ^ (y >> 30)) * static_cast<std::size_t>(0xbf58476d1ce4e5b9);
    y = (y ^ (y >> 27)) * static_cast<std::size_t>(0x94d049bb133111eb);
    y = y ^ (y >> 31);
    return y;
}
} // namespace data_structures

/**
 * @brief Test for bloom filter with string as generic type
 * @return void
 */
static void test_bloom_filter_string() {
    data_structures::BloomFilter<std::string> filter(
        10, {data_structures::hashDJB2, data_structures::hashStr});
    std::vector<std::string> toCheck{"hello", "world", "!"};
    std::vector<std::string> toFalse{"false", "world2", "!!!"};
    for (auto& x : toCheck) {
        filter.add(x);
    }
    for (auto& x : toFalse) {
        assert(filter.contains(x) == false);
    }
    for (auto& x : toCheck) {
        assert(filter.contains(x));
    }
}

/**
 * @brief Test for bloom filter with int as generic type
 * @return void
 */

Review comment (performance):
```suggestion
}  // namespace data_structures
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Tags:** Inefficient


Code after:
 * @returns hash for the `x` parameter
 */
std::size_t hashInt_1(int x) {
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = ((x >> 16) ^ x) * 0x45d9f3b;
    x = (x >> 16) ^ x;
    return x;
}

/**
 * @brief [Hash function for
 * test](https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key)
 *
 * @param x to get hash from
 * @returns hash for the `x` parameter
 */
std::size_t hashInt_2(int x) {
    auto y = static_cast<std::size_t>(x);
    y = (y ^ (y >> 30)) * static_cast<std::size_t>(0xbf58476d1ce4e5b9);
    y = (y ^ (y >> 27)) * static_cast<std::size_t>(0x94d049bb133111eb);
    y = y ^ (y >> 31);
    return y;
}
}  // namespace data_structures

/**
 * @brief Test for bloom filter with string as generic type
 * @returns void
 */
static void test_bloom_filter_string() {
    data_structures::BloomFilter<std::string> filter(
        10, {data_structures::hashDJB2, data_structures::hashStr});
    std::vector<std::string> toCheck{"hello", "world", "!"};
    std::vector<std::string> toFalse{"false", "world2", "!!!"};
    for (auto& x : toCheck) {
        filter.add(x);
    }
    for (auto& x : toFalse) {
        assert(filter.contains(x) == false);
    }
    for (auto& x : toCheck) {
        assert(filter.contains(x));
    }
}

/**
 * @brief Test for bloom filter with int as generic type
 * @returns void
 */
static void test_bloom_filter_int() {
    data_structures::BloomFilter<int> filter(
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
/**
 * @file median_search2.cpp
 *
 * @details
 * Given a linked list L[0,....,n] of n numbers, find the middle node.
 *
 * Here are some example lists you can use to see how the algorithm works
 * A = [1,2,3,4,5]
 * B = [1,2,3,4,5,6]
 * print median(A) #should be 39
 * print median(B) #should be 4
 *
 * @author [Benjamin Weiss](https://github.com/weiss-ben)
 */

/**
 * Definition for singly-linked list.
 */
struct ListNode {
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
 };
 
 #include <iostream>

Review comment (suggestion):
No need to add the filename. It's best to let Doxygen automatically detect it, otherwise, you'd have to specify the whole directory as well.
```suggestion
 * @file
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix


Code after:
/**
 * @file
 * @brief Given a linked list L[0,....,n] of n numbers, find the middle node.
 *
 * @details The technique utilized in this implementation is the ["Floyd's
 * tortoise and
 * hare"](https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare)
 * approach. This technique uses two pointers that iterate through the list at
 * different 'speeds' in order to solve problems. In this implementation, for
 * every iteration the slow pointer advances one node while the fast pointer
 * advances two nodes. The result of this is that since the fast pointer moves
 * twice as fast as the slow pointer, when the fast pointer reaches the end of
 * the list the slow pointer will be pointing to the middle node of the list.
 *
 * Here are some example lists you can use to see how the algorithm works
 * A = [1,2,3,4,5]
 * B = [1,2,3,4,5,6]
 * print median(A) #should be 39
 * print median(B) #should be 4
 *
 * @author [Benjamin Weiss](https://github.com/weiss-ben)
 * @see median_search.cpp
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
    ListNode(int x, ListNode *next) : val(x), next(next) {}
 };
 
 #include <iostream>
 #include <cassert>

/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 */
namespace median_search2 {
/**
* This function searches for the median of a linked list.
* @param head, The head of the linked list.
* @returns Median node of the linked list.
*/  
ListNode* middleNode(ListNode* head) {
    if(!head)
        return nullptr;
        
    //Fast and slow pointers
    ListNode* fastptr;
    ListNode* slowptr = fastptr = head;
    
	// fast jumps 2 while slow jumps 1    
    while(fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }
    return (fastptr->next) ? slowptr->next : slowptr;
        
}
}  // namespace median_search2
}  // namespace search

/**
 * Function to test above algorithm
 */
void test(){
	ListNode* head = new ListNode;
	head->val = 1;
	
	ListNode* temp1 = head;
	for(int i = 1; i < 6; ++i)
	{
		ListNode* temp2 = new ListNode;
		temp2->val = i;

Review comment (suggestion):
```suggestion
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation.
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Tags:** Inelegant


Code after:

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations

/**
 * Definition for singly-linked list.
 */
struct ListNode {
    int val{0};               ///< the value stored in the node
    ListNode* next{nullptr};  ///< pointer to the next node
    ListNode() = default;     ///< default constructor
    explicit ListNode(int x)
        : val(x) {}  ///< constructor with value for node->val provided
    ListNode(int x, ListNode* next)
        : val(x),
          next(next) {
    }  ///< constructor with values provided for node->val and node->next
};

/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation. Wkipedia
 * link to algorithm: https://en.wikipedia.org/wiki/Median_search
 */
namespace median_search2 {
/**
 * This function searches for the median of a linked list.
 * @param head The head of the linked list.
 * @returns Median node of the linked list.
 */
ListNode* middleNode(ListNode* head) {
    if (!head) {
        return nullptr;
    }

    // Fast and slow pointers
    ListNode* fastptr = nullptr;
    ListNode* slowptr = fastptr = head;

    // fast jumps 2 while slow jumps 1
    while (fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }

    return (fastptr->next) ? slowptr->next : slowptr;
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
* @param head, The head of the linked list.
* @returns Median node of the linked list.
*/  
ListNode* middleNode(ListNode* head) {
    if(!head)
        return nullptr;
        
    //Fast and slow pointers
    ListNode* fastptr;
    ListNode* slowptr = fastptr = head;
    
	// fast jumps 2 while slow jumps 1    
    while(fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }
    return (fastptr->next) ? slowptr->next : slowptr;
        
}
}  // namespace median_search2
}  // namespace search

/**
 * Function to test above algorithm
 */
void test(){
	ListNode* head = new ListNode;
	head->val = 1;
	
	ListNode* temp1 = head;
	for(int i = 1; i < 6; ++i)
	{
		ListNode* temp2 = new ListNode;
		temp2->val = i;
		
		temp1->next = temp2;
		temp1 = temp2;
	}
	
	ListNode* median = search::median_search2::middleNode(head);
	assert(3 == median->val);		// 3 is the value of the median node.
	std::cout << "test case:1 passed\n";
	
	// Clean up
	while(head)
	{
		ListNode* t = head->next;
		delete head;
	}
	
	ListNode* head = new ListNode;

Review comment (suggestion):
```suggestion
/**
 * @brief Self-test implementations
 * @returns void
 */
 */
static void test() {
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix&nbsp; | &nbsp;**Tags:** Not maintainable


Code after:
};

/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation. Wkipedia
 * link to algorithm: https://en.wikipedia.org/wiki/Median_search
 */
namespace median_search2 {
/**
 * This function searches for the median of a linked list.
 * @param head The head of the linked list.
 * @returns Median node of the linked list.
 */
ListNode* middleNode(ListNode* head) {
    if (!head) {
        return nullptr;
    }

    // Fast and slow pointers
    ListNode* fastptr = nullptr;
    ListNode* slowptr = fastptr = head;

    // fast jumps 2 while slow jumps 1
    while (fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }

    return (fastptr->next) ? slowptr->next : slowptr;
}
}  // namespace median_search2
}  // namespace search

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    auto* head1 = new ListNode;
    head1->val = 1;

    ListNode* temp = head1;
    for (int i = 2; i < 6; ++i) {
        // Allocate next
        auto* temp1 = new ListNode;
        temp1->val = i;
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
	
	ListNode* temp1 = head;
	for(int i = 1; i < 7; ++i)
	{
		ListNode* temp2 = new ListNode;
		temp2->val = i;
		
		temp1->next = temp2;
		temp1 = temp2;
	}
	
	ListNode* median = search::median_search2::middleNode(head);
	assert(4 == median->val);		// 3 is the value of the median node.
	std::cout << "test case:1 passed\n";
	
	// Clean up
	while(head)
	{
		ListNode* t = head->next;
		delete head;
	}
	std::cout << "--All tests passed--\n";
}

/**
 * Main function
 */
int main()
{
	test();
	return 0;
}


Review comment (suggestion):
```suggestion
 * @brief Main function
 * @returns 0 on exit
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix&nbsp; | &nbsp;**Tags:** Not maintainable


Code after:
        // Advance
        temp->next = temp1;
        temp = temp1;
    }
    temp->next = nullptr;

    ListNode* median = search::median_search2::middleNode(head1);
    assert(3 == median->val);  // 3 is the value of the median node.
    std::cout << "test case:1 passed\n";

    // Test case # 2
    auto* head2 = new ListNode;
    head2->val = 1;

    ListNode* temp2 = head2;
    for (int i = 2; i < 7; ++i) {
        // Allocate next
        auto* temp3 = new ListNode;
        temp3->val = i;

        // Advance
        temp2->next = temp3;
        temp2 = temp3;
    }
    temp2->next = nullptr;

    ListNode* median1 = search::median_search2::middleNode(head2);
    assert(4 == median1->val);  // 4 is the value of the median node.
    std::cout << "test case:2 passed\n";

    delete head1;
    delete temp;

    delete head2;
    delete temp2;

    std::cout << "--All tests passed--\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
		ListNode* temp2 = new ListNode;
		temp2->val = i;
		
		temp1->next = temp2;
		temp1 = temp2;
	}
	
	ListNode* median = search::median_search2::middleNode(head);
	assert(4 == median->val);		// 3 is the value of the median node.
	std::cout << "test case:1 passed\n";
	
	// Clean up
	while(head)
	{
		ListNode* t = head->next;
		delete head;
	}
	std::cout << "--All tests passed--\n";
}

/**
 * Main function
 */
int main()
{
	test();
	return 0;
}


Review comment (suggestion):
```suggestion
	test();  // run self-test implementations
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Tags:** Inelegant


Code after:
    temp->next = nullptr;

    ListNode* median = search::median_search2::middleNode(head1);
    assert(3 == median->val);  // 3 is the value of the median node.
    std::cout << "test case:1 passed\n";

    // Test case # 2
    auto* head2 = new ListNode;
    head2->val = 1;

    ListNode* temp2 = head2;
    for (int i = 2; i < 7; ++i) {
        // Allocate next
        auto* temp3 = new ListNode;
        temp3->val = i;

        // Advance
        temp2->next = temp3;
        temp2 = temp3;
    }
    temp2->next = nullptr;

    ListNode* median1 = search::median_search2::middleNode(head2);
    assert(4 == median1->val);  // 4 is the value of the median node.
    std::cout << "test case:2 passed\n";

    delete head1;
    delete temp;

    delete head2;
    delete temp2;

    std::cout << "--All tests passed--\n";
}

/**
 * @brief Main function
 * @returns 0 on exit
 */
int main() {
    test();  // run self-test implementations
    return 0;
}
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
* @returns Median node of the linked list.
*/  
ListNode* middleNode(ListNode* head) {
    if(!head)
        return nullptr;
        
    //Fast and slow pointers
    ListNode* fastptr;
    ListNode* slowptr = fastptr = head;
    
	// fast jumps 2 while slow jumps 1    
    while(fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }
    return (fastptr->next) ? slowptr->next : slowptr;
        
}
}  // namespace median_search2
}  // namespace search

/**
 * @brief Self-test implementations
 * @returns void
 */
 */
static void test() {
	ListNode* head = new ListNode;
	head->val = 1;
	
	ListNode* temp1 = head;
	for(int i = 1; i < 6; ++i)
	{
		ListNode* temp2 = new ListNode;
		temp2->val = i;
		
		temp1->next = temp2;
		temp1 = temp2;
	}
	
	ListNode* median = search::median_search2::middleNode(head);
	assert(3 == median->val);		// 3 is the value of the median node.
	std::cout << "test case:1 passed\n";
	
	// Clean up
	while(head)
	{
		ListNode* t = head->next;
		delete head;
	}
	

Review comment (suggestion):
There's an extra comment ending here.
```suggestion
```


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix&nbsp; | &nbsp;**Tags:** Not maintainable


Code after:
/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation. Wkipedia
 * link to algorithm: https://en.wikipedia.org/wiki/Median_search
 */
namespace median_search2 {
/**
 * This function searches for the median of a linked list.
 * @param head The head of the linked list.
 * @returns Median node of the linked list.
 */
ListNode* middleNode(ListNode* head) {
    if (!head) {
        return nullptr;
    }

    // Fast and slow pointers
    ListNode* fastptr = nullptr;
    ListNode* slowptr = fastptr = head;

    // fast jumps 2 while slow jumps 1
    while (fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }

    return (fastptr->next) ? slowptr->next : slowptr;
}
}  // namespace median_search2
}  // namespace search

/**
 * @brief Self-test implementations
 * @returns void
 */
static void test() {
    auto* head1 = new ListNode;
    head1->val = 1;

    ListNode* temp = head1;
    for (int i = 2; i < 6; ++i) {
        // Allocate next
        auto* temp1 = new ListNode;
        temp1->val = i;

        // Advance
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:
/**
 * @file
 *
 * @details
 * Given a linked list L[0,....,n] of n numbers, find the middle node. 
 * The technique utilized in this implementation is the "Floyd's tortise and hare" approach. Wikipedia link to technique: https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare
 * This technique uses two pointers that iterate through the list at different 'speeds' in order to solve problems.
 * In this implementation, for every iteration the slow pointer advances one node while the fast pointer advances two nodes. 
 * The result of this is that since the fast pointer moves twice as fast as the slow pointer, when the fast pointer reaches the end of the list 
 * the slow pointer will be pointing to the middle node of the list. 
 *
 * Here are some example lists you can use to see how the algorithm works
 * A = [1,2,3,4,5]
 * B = [1,2,3,4,5,6]
 * print median(A) #should be 39
 * print median(B) #should be 4
 *
 * @author [Benjamin Weiss](https://github.com/weiss-ben)
 */

/**
 * Definition for singly-linked list.
 */
struct ListNode {
    int val;												// The value stored in the node
    ListNode *next;											// Pointer to the next node
    ListNode() : val(0), next(nullptr) {}					// Default constructor
    ListNode(int x) : val(x), next(nullptr) {}				// Constructor with value for node->val provided
    ListNode(int x, ListNode *next) : val(x), next(next) {}	// Constructor with values provided for node->val and node->next

Review comment (suggestion):
There's still missing a brief description using `@brief`.


__
[![sema-logo](https://app.semasoftware.com/img/sema-tray-logo.gif)](https://semasoftware.com/gh) &nbsp;**Summary:** :hammer_and_wrench: This code needs a fix&nbsp; | &nbsp;**Tags:** Inelegant


Code after:
/**
 * @file
 * @brief Given a linked list L[0,....,n] of n numbers, find the middle node.
 *
 * @details The technique utilized in this implementation is the ["Floyd's
 * tortoise and
 * hare"](https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare)
 * approach. This technique uses two pointers that iterate through the list at
 * different 'speeds' in order to solve problems. In this implementation, for
 * every iteration the slow pointer advances one node while the fast pointer
 * advances two nodes. The result of this is that since the fast pointer moves
 * twice as fast as the slow pointer, when the fast pointer reaches the end of
 * the list the slow pointer will be pointing to the middle node of the list.
 *
 * Here are some example lists you can use to see how the algorithm works
 * A = [1,2,3,4,5]
 * B = [1,2,3,4,5,6]
 * print median(A) #should be 39
 * print median(B) #should be 4
 *
 * @author [Benjamin Weiss](https://github.com/weiss-ben)
 * @see median_search.cpp
 */

#include <cassert>   /// for assert
#include <iostream>  /// for IO operations

/**
 * Definition for singly-linked list.
Repository: TheAlgorithms/C-Plus-Plus
File: search/median_search2.cpp (C++)

Code before:

/**
 * Definition for singly-linked list.
 */
struct ListNode {
    int val{0};               ///< the value stored in the node
    ListNode* next{nullptr};  ///< pointer to the next node
    ListNode() {}             ///< default constructor
    explicit ListNode(int x)
        : val(x),
          next(nullptr) {}  ///< constructor with value for node->val provided
    ListNode(int x, ListNode* next)
        : val(x),
          next(next) {
    }  ///< constructor with values provided for node->val and node->next
};

/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation. Wkipedia
 * link to algorithm: https://en.wikipedia.org/wiki/Median_search
 */
namespace median_search2 {
/**
 * This function searches for the median of a linked list.
 * @param head The head of the linked list.
 * @returns Median node of the linked list.
 */
ListNode* middleNode(ListNode* head) {
    if (!head) {
        return nullptr;
    }

    // Fast and slow pointers
    ListNode* fastptr = nullptr;
    ListNode* slowptr = fastptr = head;

    // fast jumps 2 while slow jumps 1
    while (fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }
    return (fastptr->next) ? slowptr->next : slowptr;
}
}  // namespace median_search2
}  // namespace search

Review comment (suggestion):
```suggestion
 * @brief Functions for the [Median Search](https://en.wikipedia.org/wiki/Median_search) algorithm implementation.
```


Code after:
#include <iostream>  /// for IO operations

/**
 * Definition for singly-linked list.
 */
struct ListNode {
    int val{0};               ///< the value stored in the node
    ListNode* next{nullptr};  ///< pointer to the next node
    ListNode() = default;     ///< default constructor
    explicit ListNode(int x)
        : val(x) {}  ///< constructor with value for node->val provided
    ListNode(int x, ListNode* next)
        : val(x),
          next(next) {
    }  ///< constructor with values provided for node->val and node->next
};

/**
 * @namespace search
 * @brief Search algorithms
 */
namespace search {
/**
 * @namespace median_search
 * @brief Functions for the Median Search algorithm implementation. Wkipedia
 * link to algorithm: https://en.wikipedia.org/wiki/Median_search
 */
namespace median_search2 {
/**
 * This function searches for the median of a linked list.
 * @param head The head of the linked list.
 * @returns Median node of the linked list.
 */
ListNode* middleNode(ListNode* head) {
    if (!head) {
        return nullptr;
    }

    // Fast and slow pointers
    ListNode* fastptr = nullptr;
    ListNode* slowptr = fastptr = head;

    // fast jumps 2 while slow jumps 1
    while (fastptr->next && fastptr->next->next) {
        slowptr = slowptr->next;
        fastptr = fastptr->next->next;
    }

    return (fastptr->next) ? slowptr->next : slowptr;
}
}  // namespace median_search2