From: Lukáš Jiřiště Date: Sun, 5 Apr 2026 06:07:08 +0000 (+0200) Subject: Rename linked_list to llist for brevity X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=abd4e9349f8d0c92a612f247b4d9795ac2feaf96;p=Libft.git Rename linked_list to llist for brevity --- diff --git a/Makefile b/Makefile index e31ed43..ae7be26 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ SRCstruct:= ft_stack_free.c \ ft_dict_init.c \ ft_dict_insert.c \ ft_dict_traversal.c \ - ft_linked_list.c \ - ft_linked_list_helpers.c \ + ft_llist.c \ + ft_llist_helpers.c \ ft_graph.c \ ft_graph_helpers.c \ diff --git a/ft_struct/ft_graph.c b/ft_struct/ft_graph.c index f06bf4e..1cea213 100644 --- a/ft_struct/ft_graph.c +++ b/ft_struct/ft_graph.c @@ -5,7 +5,7 @@ t_ft_stat ft_graph_init(t_graph *graph, size_t el_size) if (!graph) return (invalid_input); graph->el_size = el_size; - return (ft_linked_list_init(&graph->nodes, sizeof(t_graph_node) + el_size)); + return (ft_llist_init(&graph->nodes, sizeof(t_graph_node) + el_size)); } // Static global function pointer would be more elegant @@ -36,14 +36,14 @@ void ft_graph_free(t_graph *graph, t_free_fun free_el) if (!graph) return ; handle_generic_free(1, free_el); - ft_linked_list_free(&graph->nodes, generic_free); + ft_llist_free(&graph->nodes, generic_free); return ; } void ft_graph_delete(t_graph *graph, t_graph_node *node, t_free_fun free_el) { t_graph_node **disconnecting_node; - t_linked_list_node *list_node; + t_llist_node *list_node; while (node->connected_nodes.size > 0) { @@ -51,8 +51,8 @@ void ft_graph_delete(t_graph *graph, t_graph_node *node, t_free_fun free_el) ft_graph_disconnect(node, *disconnecting_node); } handle_generic_free(1, free_el); - list_node = (t_linked_list_node *) - ((char *)node - offsetof(t_linked_list_node, data)); - ft_linked_list_delete(&graph->nodes, list_node, generic_free); + list_node = (t_llist_node *) + ((char *)node - offsetof(t_llist_node, data)); + ft_llist_delete(&graph->nodes, list_node, generic_free); return ; } diff --git a/ft_struct/ft_graph_helpers.c b/ft_struct/ft_graph_helpers.c index 30cb8ba..7c410b0 100644 --- a/ft_struct/ft_graph_helpers.c +++ b/ft_struct/ft_graph_helpers.c @@ -11,7 +11,7 @@ t_graph_node *ft_graph_insert(t_graph *graph, void *element) return (NULL); ft_memcpy(&new_node.data, element, graph->el_size); return ((t_graph_node *) - &ft_linked_list_insert(&graph->nodes, &new_node)->data); + &ft_llist_insert(&graph->nodes, &new_node)->data); } void *ft_graph_access(t_graph_node *node) diff --git a/ft_struct/ft_linked_list.c b/ft_struct/ft_llist.c similarity index 60% rename from ft_struct/ft_linked_list.c rename to ft_struct/ft_llist.c index 472794b..9303109 100644 --- a/ft_struct/ft_linked_list.c +++ b/ft_struct/ft_llist.c @@ -2,7 +2,7 @@ #include "libft.h" #include -t_ft_stat ft_linked_list_init(t_linked_list *list, size_t el_size) +t_ft_stat ft_llist_init(t_llist *list, size_t el_size) { if (!list) return (invalid_input); @@ -11,10 +11,10 @@ t_ft_stat ft_linked_list_init(t_linked_list *list, size_t el_size) return (success); } -t_linked_list_node *ft_linked_list_insert(t_linked_list *list, void *element) +t_llist_node *ft_llist_insert(t_llist *list, void *element) { - t_linked_list_node *node; - t_linked_list_node *new_node; + t_llist_node *node; + t_llist_node *new_node; if (!list || !element) return (NULL); @@ -35,15 +35,15 @@ t_linked_list_node *ft_linked_list_insert(t_linked_list *list, void *element) return (new_node); } -void *ft_linked_list_access(t_linked_list_node *node) +void *ft_llist_access(t_llist_node *node) { return (&node->data); } -void ft_linked_list_delete(t_linked_list *list, - t_linked_list_node *node, t_free_fun free_el) +void ft_llist_delete(t_llist *list, + t_llist_node *node, t_free_fun free_el) { - t_linked_list_node *parent; + t_llist_node *parent; if (!list || !list->head || !node) return ; @@ -51,28 +51,28 @@ void ft_linked_list_delete(t_linked_list *list, { list->head = node->next; if (free_el) - free_el(ft_linked_list_access(node)); + free_el(ft_llist_access(node)); free(node); return ; } parent = list->head; while (parent->next && parent->next != node) parent = parent->next; - ft_linked_list_delete_next(parent, free_el); + ft_llist_delete_next(parent, free_el); return ; } -void ft_linked_list_free(t_linked_list *list, t_free_fun free_el) +void ft_llist_free(t_llist *list, t_free_fun free_el) { - t_linked_list_node *node; - t_linked_list_node *next; + t_llist_node *node; + t_llist_node *next; node = list->head; while (node) { next = node->next; if (free_el) - free_el(ft_linked_list_access(node)); + free_el(ft_llist_access(node)); free(node); node = next; } diff --git a/ft_struct/ft_linked_list_helpers.c b/ft_struct/ft_llist_helpers.c similarity index 54% rename from ft_struct/ft_linked_list_helpers.c rename to ft_struct/ft_llist_helpers.c index ce87472..b731bcf 100644 --- a/ft_struct/ft_linked_list_helpers.c +++ b/ft_struct/ft_llist_helpers.c @@ -1,15 +1,15 @@ #include "ft_struct.h" #include -void ft_linked_list_delete_next(t_linked_list_node *node, t_free_fun free_el) +void ft_llist_delete_next(t_llist_node *node, t_free_fun free_el) { - t_linked_list_node *child; + t_llist_node *child; if (!node || !node->next) return ; child = node->next->next; if (free_el) - free_el(ft_linked_list_access(node->next)); + free_el(ft_llist_access(node->next)); free(node->next); node->next = child; return ; diff --git a/inc/ft_struct.h b/inc/ft_struct.h index 53e1db7..6e500f0 100644 --- a/inc/ft_struct.h +++ b/inc/ft_struct.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/20 16:59:43 by ljiriste #+# #+# */ -/* Updated: 2025/12/30 15:01:59 by ljiriste ### ########.fr */ +/* Updated: 2025/12/30 17:43:31 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -148,31 +148,31 @@ t_dict_entry ft_dict_traverse_full(t_dict_traversal *traversal); void *ft_dict_traverse(t_dict_traversal *traversal); void ft_dict_traversal_free(t_dict_traversal *traversal); -typedef struct s_linked_list_node t_linked_list_node; +typedef struct s_linked_list_node t_llist_node; struct s_linked_list_node { - t_linked_list_node *next; - char data[]; + t_llist_node *next; + char data[]; }; typedef struct s_linked_list { - size_t el_size; - t_linked_list_node *head; -} t_linked_list; + size_t el_size; + t_llist_node *head; +} t_llist; -t_ft_stat ft_linked_list_init(t_linked_list *list, size_t el_size); +t_ft_stat ft_llist_init(t_llist *list, size_t el_size); // Because of notoriously slow access, the insert function returns a pointer to // the inserted node instead of t_ft_stat (so the user needs not traverse). // NULL signifies an error (probably failed allocation of memory). -t_linked_list_node *ft_linked_list_insert(t_linked_list *list, void *element); -void *ft_linked_list_access(t_linked_list_node *node); -void ft_linked_list_delete(t_linked_list *list, - t_linked_list_node *node, t_free_fun free_el); -void ft_linked_list_delete_next( - t_linked_list_node *node, t_free_fun free_el); -void ft_linked_list_free(t_linked_list *list, t_free_fun free_el); +t_llist_node *ft_llist_insert(t_llist *list, void *element); +void *ft_llist_access(t_llist_node *node); +void ft_llist_delete(t_llist *list, + t_llist_node *node, t_free_fun free_el); +void ft_llist_delete_next( + t_llist_node *node, t_free_fun free_el); +void ft_llist_free(t_llist *list, t_free_fun free_el); typedef struct s_graph_node { @@ -184,7 +184,7 @@ typedef struct s_graph_node typedef struct s_graph { size_t el_size; - t_linked_list nodes; + t_llist nodes; } t_graph; t_ft_stat ft_graph_init(t_graph *graph, size_t el_size);