From bd6b4b1335f7d511b5626b9a493554985b97f9a5 Mon Sep 17 00:00:00 2001 From: Mineplay Date: Thu, 1 May 2025 04:25:49 -0500 Subject: [PATCH] feat(doubly linked list): implemented has value function --- Include/Fledasty/Core/DoublyLinkedList.h | 1 + Src/Core/DoublyLinkedList.c | 17 +++++++++++++++++ Tests/Main.c | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Include/Fledasty/Core/DoublyLinkedList.h b/Include/Fledasty/Core/DoublyLinkedList.h index 96f96ea..cc08229 100644 --- a/Include/Fledasty/Core/DoublyLinkedList.h +++ b/Include/Fledasty/Core/DoublyLinkedList.h @@ -48,6 +48,7 @@ FledastyError fledasty_doubly_linked_list_insert_at_index(FledastyDoublyLinkedLi FledastyError fledasty_doubly_linked_list_insert_before_value(FledastyDoublyLinkedList *current_doubly_linked_list, void *before_value, void *value); FledastyError fledasty_doubly_linked_list_insert_after_value(FledastyDoublyLinkedList *current_doubly_linked_list, void *after_value, void *value); +bool fledasty_doubly_linked_list_has_value(const FledastyDoublyLinkedList *current_doubly_linked_list, void *value); static inline bool fledasty_doubly_linked_list_is_empty(const FledastyDoublyLinkedList *current_doubly_linked_list) { return current_doubly_linked_list->size == 0; } #endif \ No newline at end of file diff --git a/Src/Core/DoublyLinkedList.c b/Src/Core/DoublyLinkedList.c index f9c4705..5dfda41 100644 --- a/Src/Core/DoublyLinkedList.c +++ b/Src/Core/DoublyLinkedList.c @@ -239,3 +239,20 @@ FledastyError fledasty_doubly_linked_list_insert_after_value(FledastyDoublyLinke current_doubly_linked_list->size += 1; return FLEDASTY_ERROR_NONE; } + +bool fledasty_doubly_linked_list_has_value(const FledastyDoublyLinkedList *current_doubly_linked_list, void *value) { + if (current_doubly_linked_list == NULL || value == NULL) { + return false; + } + + FledastyDoublyLinkedListNode *current_node = current_doubly_linked_list->start; + while (current_node != NULL) { + if (hallocy_compare_memory(current_node->value, value, current_doubly_linked_list->element_byte_size)) { + return true; + } + + current_node = current_node->next; + } + + return false; +} diff --git a/Tests/Main.c b/Tests/Main.c index e75e1dd..c051e36 100644 --- a/Tests/Main.c +++ b/Tests/Main.c @@ -166,8 +166,12 @@ int main() { test_doubly_linked_list_node = test_doubly_linked_list_node->previous; } + if (fledasty_linked_list_has_value(&test_linked_list, &insert_value)) { + printf("Doubly linked list contains %d\n", insert_value); + } + if (fledasty_doubly_linked_list_is_empty(&test_doubly_linked_list)) { - printf("Linked list is empty\n"); + printf("Doubly linked list is empty\n"); } fledasty_doubly_list_destroy(&test_doubly_linked_list);