Skip to content

Commit

Permalink
Merge pull request #9 from dreamer-coding/add_testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-coding authored Oct 22, 2024
2 parents 1ff3c1a + ba4c350 commit 2064a71
Show file tree
Hide file tree
Showing 26 changed files with 563 additions and 639 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Before using ToFu, ensure you have the following installed:
# ======================
[wrap-git]
url = https://github.com/fossillogic/fossil-tofu.git
revision = v0.1.3
revision = v0.1.4
[provide]
fossil-tofu = fossil_tofu_dep
Expand Down
28 changes: 0 additions & 28 deletions code/logic/doublylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,34 +159,6 @@ size_t fossil_dlist_size(const fossil_dlist_t* dlist) {
return count;
}

fossil_tofu_t* fossil_dlist_getter(fossil_dlist_t* dlist, fossil_tofu_t data) {
if (!dlist) return NULL; // Error checking for null list

fossil_dlist_node_t* current = dlist->head;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
return &(current->data);
}
current = current->next;
}
return NULL; // Not found
}

int32_t fossil_dlist_setter(fossil_dlist_t* dlist, fossil_tofu_t data) {
if (!dlist) return FOSSIL_TOFU_FAILURE; // Error checking for null list

fossil_dlist_node_t* current = dlist->head;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
// Ensure to free old data if it was dynamically allocated
current->data = data;
return FOSSIL_TOFU_SUCCESS; // Success
}
current = current->next;
}
return FOSSIL_TOFU_FAILURE; // Not found
}

bool fossil_dlist_not_empty(const fossil_dlist_t* dlist) {
return (dlist != NULL && dlist->head != NULL);
}
Expand Down
34 changes: 0 additions & 34 deletions code/logic/dqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,40 +142,6 @@ size_t fossil_dqueue_size(const fossil_dqueue_t* dqueue) {
return count;
}

fossil_tofu_t* fossil_dqueue_getter(fossil_dqueue_t* dqueue, fossil_tofu_t data) {
if (!dqueue) {
fprintf(stderr, "Error: dqueue cannot be NULL\n");
return NULL;
}

fossil_dqueue_node_t* current = dqueue->front;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
return &(current->data); // Return pointer to the found data
}
current = current->next;
}
return NULL; // Not found
}

int32_t fossil_dqueue_setter(fossil_dqueue_t* dqueue, fossil_tofu_t data) {
if (!dqueue) {
fprintf(stderr, "Error: dqueue cannot be NULL\n");
return FOSSIL_TOFU_FAILURE;
}

fossil_dqueue_node_t* current = dqueue->front;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
// Assuming `data` should replace current->data
current->data = data; // Update data
return FOSSIL_TOFU_SUCCESS; // Success
}
current = current->next;
}
return FOSSIL_TOFU_FAILURE; // Not found
}

bool fossil_dqueue_not_empty(const fossil_dqueue_t* dqueue) {
if (!dqueue) {
fprintf(stderr, "Error: dqueue cannot be NULL\n");
Expand Down
33 changes: 0 additions & 33 deletions code/logic/forwardlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,39 +141,6 @@ size_t fossil_flist_size(const fossil_flist_t* flist) {
return count;
}

fossil_tofu_t* fossil_flist_getter(fossil_flist_t* flist, fossil_tofu_t data) {
if (!flist) {
fprintf(stderr, "Error: flist cannot be NULL\n");
return NULL;
}

fossil_flist_node_t* current = flist->head;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
return &(current->data); // Return pointer to found data
}
current = current->next;
}
return NULL; // Not found
}

int32_t fossil_flist_setter(fossil_flist_t* flist, fossil_tofu_t data) {
if (!flist) {
fprintf(stderr, "Error: flist cannot be NULL\n");
return FOSSIL_TOFU_FAILURE;
}

fossil_flist_node_t* current = flist->head;
while (current) {
if (fossil_tofu_equals(current->data, data)) {
current->data = data; // Update data
return FOSSIL_TOFU_SUCCESS; // Success
}
current = current->next;
}
return FOSSIL_TOFU_FAILURE; // Not found
}

bool fossil_flist_not_empty(const fossil_flist_t* flist) {
if (!flist) {
fprintf(stderr, "Error: flist cannot be NULL\n");
Expand Down
28 changes: 0 additions & 28 deletions code/logic/fossil/tofu/doublylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,6 @@ void fossil_dlist_reverse_backward(fossil_dlist_t* dlist);
*/
size_t fossil_dlist_size(const fossil_dlist_t* dlist);

/**
* Get the data from the doubly linked list matching the specified data.
*
* @param dlist The doubly linked list from which to get the data.
* @param data The data to search for.
* @return A pointer to the matching data.
* @note Time complexity: O(n)
*/
fossil_tofu_t* fossil_dlist_getter(fossil_dlist_t* dlist, fossil_tofu_t data);

/**
* Set data in the doubly linked list.
*
* @param dlist The doubly linked list in which to set the data.
* @param data The data to set.
* @return The error code indicating the success or failure of the operation.
* @note Time complexity: O(n)
*/
int32_t fossil_dlist_setter(fossil_dlist_t* dlist, fossil_tofu_t data);

/**
* Check if the doubly linked list is not empty.
*
Expand Down Expand Up @@ -198,14 +178,6 @@ namespace fossil {
return fossil_dlist_size(dlist_);
}

fossil_tofu_t* getter(fossil_tofu_t data) {
return fossil_dlist_getter(dlist_, data);
}

void setter(fossil_tofu_t data) {
fossil_dlist_setter(dlist_, data);
}

void reverse_forward() {
fossil_dlist_reverse_forward(dlist_);
}
Expand Down
28 changes: 0 additions & 28 deletions code/logic/fossil/tofu/dqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ int32_t fossil_dqueue_search(const fossil_dqueue_t* dqueue, fossil_tofu_t data);
*/
size_t fossil_dqueue_size(const fossil_dqueue_t* dqueue);

/**
* Get the data from the dynamic queue matching the specified data.
*
* @param dqueue The dynamic queue from which to get the data.
* @param data The data to search for.
* @return A pointer to the matching data.
* @note Time complexity: O(n)
*/
fossil_tofu_t* fossil_dqueue_getter(fossil_dqueue_t* dqueue, fossil_tofu_t data);

/**
* Set data in the dynamic queue.
*
* @param dqueue The dynamic queue in which to set the data.
* @param data The data to set.
* @return The error code indicating the success or failure of the operation.
* @note Time complexity: O(n)
*/
int32_t fossil_dqueue_setter(fossil_dqueue_t* dqueue, fossil_tofu_t data);

/**
* Check if the dynamic queue is not empty.
*
Expand Down Expand Up @@ -182,14 +162,6 @@ namespace fossil {
return fossil_dqueue_size(dqueue_);
}

fossil_tofu_t* getter(fossil_tofu_t data) {
return fossil_dqueue_getter(dqueue_, data);
}

void setter(fossil_tofu_t data) {
fossil_dqueue_setter(dqueue_, data);
}

bool not_empty() {
return fossil_dqueue_not_empty(dqueue_);
}
Expand Down
28 changes: 0 additions & 28 deletions code/logic/fossil/tofu/forwardlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,6 @@ void fossil_flist_reverse_backward(fossil_flist_t* flist);
*/
size_t fossil_flist_size(const fossil_flist_t* flist);

/**
* Get the data from the forward list matching the specified data.
*
* @param flist The forward list from which to get the data.
* @param data The data to search for.
* @return A pointer to the matching data.
* @complexity O(n)
*/
fossil_tofu_t* fossil_flist_getter(fossil_flist_t* flist, fossil_tofu_t data);

/**
* Set data in the forward list.
*
* @param flist The forward list in which to set the data.
* @param data The data to set.
* @return The error code indicating the success or failure of the operation.
* @complexity O(n)
*/
int32_t fossil_flist_setter(fossil_flist_t* flist, fossil_tofu_t data);

/**
* Check if the forward list is not empty.
*
Expand Down Expand Up @@ -196,14 +176,6 @@ namespace fossil {
return fossil_flist_size(flist_);
}

fossil_tofu_t* getter(fossil_tofu_t data) {
return fossil_flist_getter(flist_, data);
}

void setter(fossil_tofu_t data) {
fossil_flist_setter(flist_, data);
}

void reverse_forward() {
fossil_flist_reverse_forward(flist_);
}
Expand Down
30 changes: 0 additions & 30 deletions code/logic/fossil/tofu/pqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,6 @@ int32_t fossil_pqueue_search(const fossil_pqueue_t* pqueue, fossil_tofu_t data,
*/
size_t fossil_pqueue_size(const fossil_pqueue_t* pqueue);

/**
* Get the data from the priority queue matching the specified data and priority.
*
* @param pqueue The priority queue from which to get the data.
* @param data The data to search for.
* @param priority The priority of the data.
* @return A pointer to the matching data, or NULL if not found.
* @note Time complexity: O(n)
*/
fossil_tofu_t* fossil_pqueue_getter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority);

/**
* Set data in the priority queue with the specified priority.
*
* @param pqueue The priority queue in which to set the data.
* @param data The data to set.
* @param priority The priority of the data.
* @return The error code indicating the success or failure of the operation.
* @note Time complexity: O(n)
*/
int32_t fossil_pqueue_setter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority);

/**
* Check if the priority queue is not empty.
*
Expand Down Expand Up @@ -184,14 +162,6 @@ namespace fossil {
return fossil_pqueue_size(pqueue_);
}

fossil_tofu_t* getter(fossil_tofu_t data, int32_t priority) {
return fossil_pqueue_getter(pqueue_, data, priority);
}

void setter(fossil_tofu_t data, int32_t priority) {
fossil_pqueue_setter(pqueue_, data, priority);
}

bool not_empty() {
return fossil_pqueue_not_empty(pqueue_);
}
Expand Down
28 changes: 0 additions & 28 deletions code/logic/fossil/tofu/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,6 @@ int32_t fossil_queue_search(const fossil_queue_t* queue, fossil_tofu_t data);
*/
size_t fossil_queue_size(const fossil_queue_t* queue);

/**
* Get the data from the queue matching the specified data.
*
* @param queue The queue from which to get the data.
* @param data The data to search for.
* @return A pointer to the matching data, or NULL if not found.
* @note Time complexity: O(n)
*/
fossil_tofu_t* fossil_queue_getter(fossil_queue_t* queue, fossil_tofu_t data);

/**
* Set data in the queue.
*
* @param queue The queue in which to set the data.
* @param data The data to set.
* @return The error code indicating the success or failure of the operation.
* @note Time complexity: O(n)
*/
int32_t fossil_queue_setter(fossil_queue_t* queue, fossil_tofu_t data);

/**
* Check if the queue is not empty.
*
Expand Down Expand Up @@ -181,14 +161,6 @@ namespace fossil {
return fossil_queue_size(queue_);
}

fossil_tofu_t* getter(fossil_tofu_t data) {
return fossil_queue_getter(queue_, data);
}

void setter(fossil_tofu_t data) {
fossil_queue_setter(queue_, data);
}

bool not_empty() {
return fossil_queue_not_empty(queue_);
}
Expand Down
28 changes: 0 additions & 28 deletions code/logic/fossil/tofu/setof.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,6 @@ int32_t fossil_set_search(const fossil_set_t* set, fossil_tofu_t data);
*/
size_t fossil_set_size(const fossil_set_t* set);

/**
* Get the data from the set matching the specified data.
*
* @param set The set from which to get the data.
* @param data The data to search for.
* @return A pointer to the matching data, or NULL if not found.
* @note O(n) - Linear time complexity, where n is the number of elements in the set.
*/
fossil_tofu_t* fossil_set_getter(fossil_set_t* set, fossil_tofu_t data);

/**
* Set data in the set.
*
* @param set The set in which to set the data.
* @param data The data to set.
* @return The error code indicating the success or failure of the operation.
* @note O(n) - Linear time complexity, where n is the number of elements in the set.
*/
int32_t fossil_set_setter(fossil_set_t* set, fossil_tofu_t data);

/**
* Check if the set is not empty.
*
Expand Down Expand Up @@ -188,14 +168,6 @@ namespace fossil {
return fossil_set_size(set_);
}

fossil_tofu_t* getter(fossil_tofu_t data) {
return fossil_set_getter(set_, data);
}

void setter(fossil_tofu_t data) {
fossil_set_setter(set_, data);
}

bool not_empty() {
return fossil_set_not_empty(set_);
}
Expand Down
Loading

0 comments on commit 2064a71

Please sign in to comment.