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