aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/libft.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/inc/libft.h b/inc/libft.h
index 05a5ae9..48b2c0b 100644
--- a/inc/libft.h
+++ b/inc/libft.h
@@ -135,4 +135,33 @@ void ft_putendl_fd (char *s, int fd);
/** @brief Write integer @p n in decimal to @p fd. */
void ft_putnbr_fd (int n, int fd);
+/* ======================================
+ * Linked list
+ * ====================================== */
+
+typedef struct s_list
+{
+ void *content; /**< Node payload (owned by the caller). */
+ struct s_list *next; /**< Next node, or NULL for the tail. */
+} t_list;
+
+/** @brief Allocate a new list node with @p content; next is NULL. */
+t_list *ft_lstnew (void *content);
+/** @brief Prepend @p new to the list pointed to by @p lst. */
+void ft_lstadd_front (t_list **lst, t_list *new);
+/** @brief Count the number of nodes in @p lst. */
+int ft_lstsize (t_list *lst);
+/** @brief Return the last node of @p lst. */
+t_list *ft_lstlast (t_list *lst);
+/** @brief Append @p new to the end of the list pointed to by @p lst. */
+void ft_lstadd_back (t_list **lst, t_list *new);
+/** @brief Delete one node's content with @p del and free the node. */
+void ft_lstdelone (t_list *lst, void (*del) (void *));
+/** @brief Delete and free all nodes in @p lst using @p del; set *lst=NULL. */
+void ft_lstclear (t_list **lst, void (*del) (void *));
+/** @brief Apply @p f to the content of each node in @p lst. */
+void ft_lstiter (t_list *lst, void (*f) (void *));
+/** @brief Map @p f over @p lst, creating a new list; use @p del on failure. */
+t_list *ft_lstmap (t_list *lst, void *(*f) (void *), void (*del) (void *));
+
#endif