Function renaming and moving.

This commit is contained in:
metallaxis committed 2026-05-07 10:14:38 +03:00
1 parent e3239bf564
commit 77631299b8
6 files changed
+48 -47

No files matched your search

+6 -6
View File
@@ -8,34 +8,34 @@
* @brief Initializes the queue with a maximum number of elements
* @param max_elements The maximum number of elements the queue can hold
*/
void q_init(int max_elements);
void queue_init(int max_elements);
/**
* @brief Pushes a node into the queue
* @param n The node to push into the queue
*/
void q_push(Node* n);
void queue_push(Node* n);
/**
* @brief Returns the node from the front of the queue
* @return The node from the front of the queue
*/
Node* q_pop();
Node* queue_pop();
/**
* @brief Returns the current size of the queue
* @return The current size of the queue
*/
int q_size();
int queue_size();
/**
* @brief Clears the queue without freeing memory
*/
void q_clear();
void queue_clear();
/**
* @brief Reset the queue memory
*/
void q_destroy();
void queue_destroy();
#endif
+4 -4
View File
@@ -8,7 +8,7 @@
int run_bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode) {
node_pool_reset();
q_clear();
queue_clear();
clear_hash_table();
Node* root = node_pool_alloc();
@@ -17,12 +17,12 @@ int run_bfs(int128_t* sum, int128_t a0, int128_t b0, int128_t c0, int print_mode
root->a = a0; root->b = b0; root->c = c0;
root->move = '\0'; root->parent = NULL;
q_push(root);
queue_push(root);
visit_and_mark(a0, b0, c0);
Node* found = NULL;
while (q_size() > 0) {
Node* curr = q_pop();
while (queue_size() > 0) {
Node* curr = queue_pop();
/* Goal Check */
if (curr->a == 0 || curr->b == 0 || curr->c == 0) {
+3 -1
View File
@@ -24,6 +24,7 @@ void node_pool_init(int max_nodes) {
pool_ptr = 0;
visited_ptr = 0;
for (size_t i = 0; i < HASH_SIZE; ++i) hash_table[i] = NULL;
queue_init(max_nodes);
}
Node* node_pool_alloc() {
@@ -40,6 +41,7 @@ void node_pool_reset() {
void node_pool_destroy() {
if (pool) free(pool);
queue_destroy();
}
int node_pool_usage() {
@@ -67,7 +69,7 @@ static void make_move(char move, Node* curr) {
n->move = move;
n->parent = curr;
n->next = NULL;
q_push(n);
queue_push(n);
}
}
}
+23 -23
View File
@@ -2,41 +2,41 @@
#include <stdio.h>
#include <stdlib.h>
static Node* q_front = NULL;
static Node* q_back = NULL;
static Node* queue_front = NULL;
static Node* queue_back = NULL;
static int current_size = 0;
static int capacity = 0;
void q_init(int max_elements) {
void queue_init(int max_elements) {
capacity = max_elements;
q_front = NULL;
q_back = NULL;
queue_front = NULL;
queue_back = NULL;
current_size = 0;
}
void q_push(Node* n) {
void queue_push(Node* n) {
if (current_size >= capacity) return; /* Pool safety */
/* Exact logic from your 'enqueue' function */
n->next = NULL;
if (!q_back) {
q_front = q_back = n;
if (!queue_back) {
queue_front = queue_back = n;
} else {
q_back->next = n;
q_back = n;
queue_back->next = n;
queue_back = n;
}
current_size++;
}
Node* q_pop() {
Node* queue_pop() {
/* Exact logic from your 'dequeue' function */
if (!q_front) return NULL;
if (!queue_front) return NULL;
Node* r = q_front;
q_front = q_front->next;
Node* r = queue_front;
queue_front = queue_front->next;
if (!q_front) {
q_back = NULL;
if (!queue_front) {
queue_back = NULL;
}
r->next = NULL; /* Clean up the link */
@@ -45,19 +45,19 @@ Node* q_pop() {
return r;
}
int q_size() {
int queue_size() {
return current_size;
}
void q_clear() {
q_front = NULL;
q_back = NULL;
void queue_clear() {
queue_front = NULL;
queue_back = NULL;
current_size = 0;
}
void q_destroy() {
q_front = NULL;
q_back = NULL;
void queue_destroy() {
queue_front = NULL;
queue_back = NULL;
current_size = 0;
capacity = 0;
}
+3 -4
View File
@@ -49,8 +49,8 @@ void clear_global_table() {
}
int main() {
node_pool_init(20000000);
q_init(20000000);
// Good for p = 7: 80000000
node_pool_init(160000000);
int mode = 0, print_mode = 0;
int128_t a0 = 10, b0 = 6, c0 = 0, sum = 0;
@@ -100,7 +100,7 @@ int main() {
}
else if (mode == 2) {
clear_global_table(); /* Reset unique root tracker */
int p = 6;
int p = 7;
int exponents[3] = {2*p + 2, p, p};
int128_t values[3] = {4 * power(a0, p) * power(b0, p), power(a0, p), power(b0, p)};
generate_factor_pairs(&sum, 0, exponents, values, 1, print_mode);
@@ -110,6 +110,5 @@ int main() {
}
node_pool_destroy();
q_destroy();
return 0;
}
+9 -9
View File
@@ -65,23 +65,23 @@ static int visit_and_mark(int128_t a, int128_t b, int128_t c) {
return 1;
}
static Node *q_front = NULL;
static Node *q_back = NULL;
static Node *queue_front = NULL;
static Node *queue_back = NULL;
static void enqueue(Node *n) {
n->next = NULL;
if (!q_back) q_front = q_back = n;
if (!queue_back) queue_front = queue_back = n;
else {
q_back->next = n;
q_back = n;
queue_back->next = n;
queue_back = n;
}
}
static Node *dequeue(void) {
if (!q_front) return NULL;
Node *r = q_front;
q_front = q_front->next;
if (!q_front) q_back = NULL;
if (!queue_front) return NULL;
Node *r = queue_front;
queue_front = queue_front->next;
if (!queue_front) queue_back = NULL;
r->next = NULL;
return r;
}