From 3e04e24b1cacb777c089dfb3af4e25daf2902aed Mon Sep 17 00:00:00 2001 From: Mineplay Date: Sat, 19 Apr 2025 15:14:30 -0500 Subject: [PATCH 1/6] feat(queue): added queue datastructure with init and destroy function --- Include/Fledasty/Core/Queue.h | 43 ++++++++++++++++++++++ Include/Fledasty/Utils/Error.h | 32 +++++++++++++++++ Src/Core/Queue.c | 66 ++++++++++++++++++++++++++++++++++ Tests/Main.c | 7 +++- 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 Include/Fledasty/Core/Queue.h create mode 100644 Include/Fledasty/Utils/Error.h create mode 100644 Src/Core/Queue.c diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h new file mode 100644 index 0000000..70a3c9e --- /dev/null +++ b/Include/Fledasty/Core/Queue.h @@ -0,0 +1,43 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Queue.h + * Description: + * This file contains the Queue structure and the functions for modifying it. + * It includes functions to Push, Pop, Peek and check if empty. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef FLEDASTY_QUEUE +#define FLEDASTY_QUEUE + +#include + +#include "../Utils/Error.h" + +typedef struct FledastyQueueNode { + void *value; + struct FledastyQueueNode *previous, *next; +} FledastyQueueNode; + +typedef struct { + size_t size; + FledastyQueueNode *start, *end; +} FledastyQueue; + +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue); +FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); + +#endif \ No newline at end of file diff --git a/Include/Fledasty/Utils/Error.h b/Include/Fledasty/Utils/Error.h new file mode 100644 index 0000000..c981843 --- /dev/null +++ b/Include/Fledasty/Utils/Error.h @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Error.h + * Description: + * This file contains the ErrorCode enum that defines the error codes for the + * library. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#ifndef FLEDASTY_ERROR +#define FLEDASTY_ERROR + +typedef enum { + FLEDASTY_ERROR_NONE = 0, + FLEDASTY_ERROR_ALLOCATION = 1, + FLEDASTY_ERROR_INVALID_POINTER = 2, +} FledastyError; + +#endif \ No newline at end of file diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c new file mode 100644 index 0000000..b9108af --- /dev/null +++ b/Src/Core/Queue.c @@ -0,0 +1,66 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * File: Main.c + * Description: + * Executes all tests. + * + * Author: Mineplay + * ----------------------------------------------------------------------------- + */ +#include "../../Include/Fledasty/Core/Queue.h" + +#include +#include + +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue) { + if (new_queue == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + new_queue->size = 0; + new_queue->start = NULL; + new_queue->end = NULL; + + return FLEDASTY_ERROR_NONE; +} + +FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) { + if (current_queue == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + FledastyQueueNode *previousNode = NULL; + FledastyQueueNode *current_node = current_queue->start; + while (current_node != NULL) { + previousNode = current_node; + current_node = current_node->next; + + HallocyError error = hallocy_free(previousNode->value); + if (error != HALLOCY_ERROR_NONE) { + return FLEDASTY_ERROR_ALLOCATION; + } + + error = hallocy_free(previousNode); + if (error != HALLOCY_ERROR_NONE) { + return FLEDASTY_ERROR_ALLOCATION; + } + } + + current_queue->size = 0; + current_queue->start = NULL; + current_queue->end = NULL; + + return FLEDASTY_ERROR_NONE; +} \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index cde1df7..d2da10b 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -20,8 +20,13 @@ * ----------------------------------------------------------------------------- */ #include +#include int main() { - printf("Test\n"); + FledastyQueue test_queue; + fledasty_queue_initialize(&test_queue); + fledasty_queue_destroy(&test_queue); + + printf("Done\n"); return 0; } \ No newline at end of file -- 2.39.5 From 04744bb89042f79e049b71b7afeff874ac319ca9 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Sun, 20 Apr 2025 09:08:59 -0500 Subject: [PATCH 2/6] feat(queue): added push function to queue --- Include/Fledasty/Core/Queue.h | 2 ++ Include/Fledasty/Utils/Error.h | 2 +- Src/Core/Queue.c | 35 ++++++++++++++++++++++++++++++++-- Tests/Main.c | 12 ++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index 70a3c9e..b0e6a34 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -40,4 +40,6 @@ typedef struct { FledastyError fledasty_queue_initialize(FledastyQueue *new_queue); FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); +FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value, const size_t size); + #endif \ No newline at end of file diff --git a/Include/Fledasty/Utils/Error.h b/Include/Fledasty/Utils/Error.h index c981843..91f5dc7 100644 --- a/Include/Fledasty/Utils/Error.h +++ b/Include/Fledasty/Utils/Error.h @@ -25,7 +25,7 @@ typedef enum { FLEDASTY_ERROR_NONE = 0, - FLEDASTY_ERROR_ALLOCATION = 1, + FLEDASTY_ERROR_FAILED_ALLOCATION = 1, FLEDASTY_ERROR_INVALID_POINTER = 2, } FledastyError; diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index b9108af..6f3a41a 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -23,6 +23,7 @@ #include #include +#include FledastyError fledasty_queue_initialize(FledastyQueue *new_queue) { if (new_queue == NULL) { @@ -49,12 +50,12 @@ FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) { HallocyError error = hallocy_free(previousNode->value); if (error != HALLOCY_ERROR_NONE) { - return FLEDASTY_ERROR_ALLOCATION; + return FLEDASTY_ERROR_FAILED_ALLOCATION; } error = hallocy_free(previousNode); if (error != HALLOCY_ERROR_NONE) { - return FLEDASTY_ERROR_ALLOCATION; + return FLEDASTY_ERROR_FAILED_ALLOCATION; } } @@ -62,5 +63,35 @@ FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) { current_queue->start = NULL; current_queue->end = NULL; + return FLEDASTY_ERROR_NONE; +} + +FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value, const size_t size) { + if (current_queue == NULL || value == NULL) { + return FLEDASTY_ERROR_INVALID_POINTER; + } + + FledastyQueueNode *new_queue_node = (FledastyQueueNode*)hallocy_malloc(sizeof(FledastyQueueNode)); + if (new_queue_node == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + new_queue_node->value = (FledastyQueueNode*)hallocy_malloc(size); + hallocy_copy_memory(new_queue_node->value, value, size); + + new_queue_node->next = NULL; + if (current_queue->start == NULL) { + current_queue->start = new_queue_node; + current_queue->end = new_queue_node; + + new_queue_node->previous = NULL; + } else { + new_queue_node->previous = current_queue->end; + + current_queue->end->next = new_queue_node; + current_queue->end = new_queue_node; + } + + current_queue->size += 1; return FLEDASTY_ERROR_NONE; } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index d2da10b..4a0fac6 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -25,6 +25,18 @@ int main() { FledastyQueue test_queue; fledasty_queue_initialize(&test_queue); + + int value = 10; + for (int i = 0; i < 10; i += 1) { + fledasty_queue_push(&test_queue, &i, sizeof(int)); + } + + FledastyQueueNode *current_node = test_queue.start; + for (int i = 0; i < test_queue.size; i++) { + printf("Element %d\n", *((int*)current_node->value)); + current_node = current_node->next; + } + fledasty_queue_destroy(&test_queue); printf("Done\n"); -- 2.39.5 From d831ad34092fa8a43b26caa6f56188bee2d18042 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Mon, 21 Apr 2025 13:10:44 -0500 Subject: [PATCH 3/6] perf(queue): improved performance of queue by changing to dynamic list instead of doubly linked list --- Include/Fledasty/Core/Queue.h | 16 ++++---- Src/Core/Queue.c | 71 ++++++++++++++--------------------- Tests/Main.c | 11 +----- 3 files changed, 37 insertions(+), 61 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index b0e6a34..44aad6b 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -27,19 +27,17 @@ #include "../Utils/Error.h" -typedef struct FledastyQueueNode { - void *value; - struct FledastyQueueNode *previous, *next; -} FledastyQueueNode; - typedef struct { - size_t size; - FledastyQueueNode *start, *end; + size_t size, capacity; + size_t head, tail; + + size_t element_byte_size; + unsigned char *buffer; } FledastyQueue; -FledastyError fledasty_queue_initialize(FledastyQueue *new_queue); +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t element_byte_size); FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); -FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value, const size_t size); +FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); #endif \ No newline at end of file diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index 6f3a41a..12de23e 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -12,9 +12,10 @@ * limitations under the License. * * ----------------------------------------------------------------------------- - * File: Main.c + * File: Queue.c * Description: - * Executes all tests. + * This file contains the functions for modifying the queue. It includes functions + * to Push, Pop, Peek and check if empty. * * Author: Mineplay * ----------------------------------------------------------------------------- @@ -22,17 +23,26 @@ #include "../../Include/Fledasty/Core/Queue.h" #include +#include #include #include -FledastyError fledasty_queue_initialize(FledastyQueue *new_queue) { +FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t element_byte_size) { if (new_queue == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; } new_queue->size = 0; - new_queue->start = NULL; - new_queue->end = NULL; + new_queue->capacity = 10; + new_queue->element_byte_size = element_byte_size; + + new_queue->buffer = (unsigned char*)hallocy_malloc(new_queue->capacity * element_byte_size); + if (new_queue->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } + + new_queue->head = 0; + new_queue->tail = 0; return FLEDASTY_ERROR_NONE; } @@ -42,55 +52,30 @@ FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) { return FLEDASTY_ERROR_INVALID_POINTER; } - FledastyQueueNode *previousNode = NULL; - FledastyQueueNode *current_node = current_queue->start; - while (current_node != NULL) { - previousNode = current_node; - current_node = current_node->next; - - HallocyError error = hallocy_free(previousNode->value); - if (error != HALLOCY_ERROR_NONE) { - return FLEDASTY_ERROR_FAILED_ALLOCATION; - } - - error = hallocy_free(previousNode); - if (error != HALLOCY_ERROR_NONE) { - return FLEDASTY_ERROR_FAILED_ALLOCATION; - } + HallocyError result = hallocy_free(current_queue->buffer); + if (result != HALLOCY_ERROR_NONE) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; } - current_queue->size = 0; - current_queue->start = NULL; - current_queue->end = NULL; - + current_queue->buffer = NULL; return FLEDASTY_ERROR_NONE; } -FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value, const size_t size) { +FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { if (current_queue == NULL || value == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; } - FledastyQueueNode *new_queue_node = (FledastyQueueNode*)hallocy_malloc(sizeof(FledastyQueueNode)); - if (new_queue_node == NULL) { - return FLEDASTY_ERROR_FAILED_ALLOCATION; + if (current_queue->capacity <= current_queue->size + 1) { + current_queue->capacity = current_queue->capacity + (current_queue->capacity / 2); + current_queue->buffer = (unsigned char*)hallocy_realloc(current_queue->buffer, current_queue->capacity * current_queue->element_byte_size); + + if (current_queue->buffer == NULL) { + return FLEDASTY_ERROR_FAILED_ALLOCATION; + } } - new_queue_node->value = (FledastyQueueNode*)hallocy_malloc(size); - hallocy_copy_memory(new_queue_node->value, value, size); - - new_queue_node->next = NULL; - if (current_queue->start == NULL) { - current_queue->start = new_queue_node; - current_queue->end = new_queue_node; - - new_queue_node->previous = NULL; - } else { - new_queue_node->previous = current_queue->end; - - current_queue->end->next = new_queue_node; - current_queue->end = new_queue_node; - } + hallocy_copy_memory(current_queue->buffer + (current_queue->size * current_queue->element_byte_size), value, current_queue->element_byte_size); current_queue->size += 1; return FLEDASTY_ERROR_NONE; diff --git a/Tests/Main.c b/Tests/Main.c index 4a0fac6..f07647b 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -24,17 +24,10 @@ int main() { FledastyQueue test_queue; - fledasty_queue_initialize(&test_queue); + fledasty_queue_initialize(&test_queue, sizeof(int)); - int value = 10; for (int i = 0; i < 10; i += 1) { - fledasty_queue_push(&test_queue, &i, sizeof(int)); - } - - FledastyQueueNode *current_node = test_queue.start; - for (int i = 0; i < test_queue.size; i++) { - printf("Element %d\n", *((int*)current_node->value)); - current_node = current_node->next; + fledasty_queue_push(&test_queue, &i); } fledasty_queue_destroy(&test_queue); -- 2.39.5 From 160f6b513e128751971a50dc1b93684fe9e023a9 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Mon, 21 Apr 2025 15:14:06 -0500 Subject: [PATCH 4/6] feat(queue): implemented peek function --- Include/Fledasty/Core/Queue.h | 1 + Src/Core/Queue.c | 21 +++++++++++++++++++-- Tests/Main.c | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index 44aad6b..abc9e63 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -39,5 +39,6 @@ FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, const size_t e FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); +void *fledasty_queue_peek(FledastyQueue *current_queue); #endif \ No newline at end of file diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index 12de23e..c700c58 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -66,17 +66,34 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { return FLEDASTY_ERROR_INVALID_POINTER; } - if (current_queue->capacity <= current_queue->size + 1) { + if (current_queue->size == current_queue->capacity) { current_queue->capacity = current_queue->capacity + (current_queue->capacity / 2); current_queue->buffer = (unsigned char*)hallocy_realloc(current_queue->buffer, current_queue->capacity * current_queue->element_byte_size); if (current_queue->buffer == NULL) { return FLEDASTY_ERROR_FAILED_ALLOCATION; } + + size_t new_tail = current_queue->capacity - current_queue->tail; + hallocy_move_memory(current_queue->buffer + (current_queue->tail * current_queue->element_byte_size), current_queue->buffer + (new_tail * current_queue->element_byte_size), current_queue->size - current_queue->tail); + current_queue->tail = new_tail; } - hallocy_copy_memory(current_queue->buffer + (current_queue->size * current_queue->element_byte_size), value, current_queue->element_byte_size); + hallocy_copy_memory(current_queue->buffer + (current_queue->head * current_queue->element_byte_size), value, current_queue->element_byte_size); current_queue->size += 1; + current_queue->head += 1; + if (current_queue->head >= current_queue->capacity) { + current_queue->head = 0; + } + return FLEDASTY_ERROR_NONE; +} + +void *fledasty_queue_peek(FledastyQueue *current_queue) { + if (current_queue == NULL) { + return NULL; + } + + return current_queue->buffer + (current_queue->tail * current_queue->element_byte_size); } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index f07647b..1a03f6f 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -30,6 +30,9 @@ int main() { fledasty_queue_push(&test_queue, &i); } + int *peek_data = (int*)fledasty_queue_peek(&test_queue); + printf("Peeked: %d\n", *peek_data); + fledasty_queue_destroy(&test_queue); printf("Done\n"); -- 2.39.5 From 9893d2f2684537801435e23af5332cb33798e324 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Mon, 21 Apr 2025 15:30:49 -0500 Subject: [PATCH 5/6] feat(queue): added pop function to queue --- Include/Fledasty/Core/Queue.h | 1 + Src/Core/Queue.c | 38 ++++++++++++++++++++++++++--------- Tests/Main.c | 5 +++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index abc9e63..e018653 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -40,5 +40,6 @@ FledastyError fledasty_queue_destroy(FledastyQueue *current_queue); FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); void *fledasty_queue_peek(FledastyQueue *current_queue); +void *fledasty_queue_pop(FledastyQueue *current_queue); #endif \ No newline at end of file diff --git a/Src/Core/Queue.c b/Src/Core/Queue.c index c700c58..1711c8d 100644 --- a/Src/Core/Queue.c +++ b/Src/Core/Queue.c @@ -60,7 +60,7 @@ FledastyError fledasty_queue_destroy(FledastyQueue *current_queue) { current_queue->buffer = NULL; return FLEDASTY_ERROR_NONE; } - +#include FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { if (current_queue == NULL || value == NULL) { return FLEDASTY_ERROR_INVALID_POINTER; @@ -73,18 +73,19 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value) { if (current_queue->buffer == NULL) { return FLEDASTY_ERROR_FAILED_ALLOCATION; } - - size_t new_tail = current_queue->capacity - current_queue->tail; - hallocy_move_memory(current_queue->buffer + (current_queue->tail * current_queue->element_byte_size), current_queue->buffer + (new_tail * current_queue->element_byte_size), current_queue->size - current_queue->tail); - current_queue->tail = new_tail; + printf("Allocated\n"); + size_t new_head = current_queue->capacity - current_queue->head; + hallocy_move_memory(current_queue->buffer + (current_queue->head * current_queue->element_byte_size), current_queue->buffer + (new_head * current_queue->element_byte_size), current_queue->size - current_queue->tail); + current_queue->head = new_head; } - hallocy_copy_memory(current_queue->buffer + (current_queue->head * current_queue->element_byte_size), value, current_queue->element_byte_size); + hallocy_copy_memory(current_queue->buffer + (current_queue->tail * current_queue->element_byte_size), value, current_queue->element_byte_size); current_queue->size += 1; - current_queue->head += 1; - if (current_queue->head >= current_queue->capacity) { - current_queue->head = 0; + current_queue->tail += 1; + if (current_queue->tail >= current_queue->capacity) { + printf("To 0\n"); + current_queue->tail = 0; } return FLEDASTY_ERROR_NONE; @@ -95,5 +96,22 @@ void *fledasty_queue_peek(FledastyQueue *current_queue) { return NULL; } - return current_queue->buffer + (current_queue->tail * current_queue->element_byte_size); + return current_queue->buffer + (current_queue->head * current_queue->element_byte_size); +} + +void *fledasty_queue_pop(FledastyQueue *current_queue) { + if (current_queue == NULL || current_queue->size == 0) { + return NULL; + } + + void *value_address = current_queue->buffer + (current_queue->head * current_queue->element_byte_size); + + current_queue->size -= 1; + if (current_queue->head == current_queue->capacity) { + current_queue->head = 0; + } else { + current_queue->head += 1; + } + + return value_address; } \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index 1a03f6f..d2222fa 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -33,6 +33,11 @@ int main() { int *peek_data = (int*)fledasty_queue_peek(&test_queue); printf("Peeked: %d\n", *peek_data); + for (int i = test_queue.size; i > 0; i -= 1) { + int *popped_data = (int*)fledasty_queue_pop(&test_queue); + printf("Popped: %d\n", *popped_data); + } + fledasty_queue_destroy(&test_queue); printf("Done\n"); -- 2.39.5 From c7892da31b1d842d80268adfd720726966292797 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Tue, 22 Apr 2025 15:23:51 -0500 Subject: [PATCH 6/6] feat(queue): added is empty function to queue --- Include/Fledasty/Core/Queue.h | 2 ++ Tests/Main.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Include/Fledasty/Core/Queue.h b/Include/Fledasty/Core/Queue.h index e018653..8b168fc 100644 --- a/Include/Fledasty/Core/Queue.h +++ b/Include/Fledasty/Core/Queue.h @@ -42,4 +42,6 @@ FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value); void *fledasty_queue_peek(FledastyQueue *current_queue); void *fledasty_queue_pop(FledastyQueue *current_queue); +static inline size_t fledasty_queue_is_empty(FledastyQueue *current_queue) { return current_queue->size == 0; } + #endif \ No newline at end of file diff --git a/Tests/Main.c b/Tests/Main.c index d2222fa..1097b69 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -38,6 +38,10 @@ int main() { printf("Popped: %d\n", *popped_data); } + if (fledasty_queue_is_empty(&test_queue)) { + printf("Queue is empty\n"); + } + fledasty_queue_destroy(&test_queue); printf("Done\n"); -- 2.39.5