Conversation
|
Resolves issue #78 |
|
|
||
| *out_size = count; | ||
|
|
||
| Node_free(head); |
There was a problem hiding this comment.
Memory leak: head no longer points to the tree root after the loop on lines 229-237. Only the subtree from head downward is freed here, not the entire tree. The tree root should be stored separately and freed here.
To fix this, use the same pattern suggested in the previous comment - store the root separately:
Node *root = generate_tree(primes, prime_count);
// ... rest of code ...
Node_free(root); // Free the entire tree, not just the subtree| for (int i = 0; i < size; ++i) { | ||
| snprintf(buffer, sizeof(buffer), "%d", list[i]); | ||
| Node *head = root; | ||
| for (int j = 0; j < strlen(buffer); ++j) { |
There was a problem hiding this comment.
Performance issue: strlen(buffer) is called on every iteration of the loop. Since the buffer content doesn't change during the loop, this should be computed once before the loop.
Change to:
size_t buffer_len = strlen(buffer);
for (int j = 0; j < buffer_len; ++j) {| for (int j = 0; j < strlen(buffer); ++j) { | |
| size_t buffer_len = strlen(buffer); | |
| for (int j = 0; j < buffer_len; ++j) { |
There was a problem hiding this comment.
Supposedly matches the behavior of other benchmarks
|
|
||
| int result_size; | ||
| int *result = find(UPPER_BOUND, PREFIX, &result_size); | ||
|
|
There was a problem hiding this comment.
Potential null pointer dereference: If find returns NULL (when the prefix is not found), to_string will be called with a NULL pointer, which will cause undefined behavior.
Add a null check:
int *result = find(UPPER_BOUND, PREFIX, &result_size);
if (result == NULL) {
printf("[]\n");
printf("Execution time: 0.00ms\n");
return 0;
}| if (result == NULL) { | |
| printf("[]\n"); | |
| printf("Execution time: 0.00ms\n"); | |
| return 0; | |
| } |
There was a problem hiding this comment.
Execution time must be actual if this is added
Implement Sieve of Atkins algorithm in C for benchmark suite
Summary
Implements
primes/Atkinbenchmark inC.Checklist
Please review CONTRIBUTING.md for detailed guidelines.
langs/<language>/<algorithm>/<Name>.<ext>benchmark.ymlin language directoryfeat(<language>): add <algorithm>/<Name> benchmarkVerification
Example:
langs/php/primes/Simple.phpNotes
Original Description
Implement Sieve of Atkins algorithm in C for benchmark suite
Output:
[323381, 323383, 3233803, 3233809, 3233851, 3233863, 3233873, 3233887, 3233897]
Execution time: 236.57ms
=== Code Execution Successful ===