From d3908006349f38bcfc0151daebd98b6873a2dbfc Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 6 Feb 2023 18:28:28 +0100 Subject: libcnary: Updated typedefs of node_t and node_list_t to contain pointer This makes the code more readable. Obviously all the code that uses it is also updated. --- libcnary/node_list.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'libcnary/node_list.c') diff --git a/libcnary/node_list.c b/libcnary/node_list.c index aee3bd6..f6c2c70 100644 --- a/libcnary/node_list.c +++ b/libcnary/node_list.c @@ -28,12 +28,14 @@ #include "node.h" #include "node_list.h" -void node_list_destroy(node_list_t* list) { +void node_list_destroy(node_list_t list) +{ free(list); } -node_list_t* node_list_create() { - node_list_t* list = (node_list_t*)calloc(1, sizeof(node_list_t)); +node_list_t node_list_create() +{ + node_list_t list = (node_list_t)calloc(1, sizeof(struct node_list)); if (list == NULL) { return NULL; } @@ -45,11 +47,12 @@ node_list_t* node_list_create() { return list; } -int node_list_add(node_list_t* list, node_t* node) { +int node_list_add(node_list_t list, node_t node) +{ if (!list || !node) return -1; // Find the last element in the list - node_t* last = list->end; + node_t last = list->end; // Setup our new node as the new last element node->next = NULL; @@ -72,17 +75,18 @@ int node_list_add(node_list_t* list, node_t* node) { return 0; } -int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) { +int node_list_insert(node_list_t list, unsigned int node_index, node_t node) +{ if (!list || !node) return -1; if (node_index >= list->count) { return node_list_add(list, node); } // Get the first element in the list - node_t* cur = list->begin; + node_t cur = list->begin; unsigned int pos = 0; - node_t* prev = NULL; + node_t prev = NULL; if (node_index > 0) { while (pos < node_index) { @@ -120,15 +124,16 @@ int node_list_insert(node_list_t* list, unsigned int node_index, node_t* node) { return 0; } -int node_list_remove(node_list_t* list, node_t* node) { +int node_list_remove(node_list_t list, node_t node) +{ if (!list || !node) return -1; if (list->count == 0) return -1; int node_index = 0; - node_t* n; + node_t n; for (n = list->begin; n; n = n->next) { if (node == n) { - node_t* newnode = node->next; + node_t newnode = node->next; if (node->prev) { node->prev->next = newnode; if (newnode) { @@ -153,4 +158,3 @@ int node_list_remove(node_list_t* list, node_t* node) { } return -1; } - -- cgit v1.1-32-gdbae