]> git.lizzy.rs Git - dragonstd.git/blobdiff - list.h
Add array_idx
[dragonstd.git] / list.h
diff --git a/list.h b/list.h
index 5adb33e96caae6816bd1162b87df0fc72aed6005..9e03023e2cf48cad86b072c9ebc356c7693822f6 100644 (file)
--- a/list.h
+++ b/list.h
@@ -8,7 +8,8 @@
 #ifndef _DRAGONSTD_LIST_H_ // include guard
 #define _DRAGONSTD_LIST_H_
 
-#include "bits/callback.h" // for Iterator, Comparator
+#include <stdbool.h>       // for bool
+#include "bits/compare.h"  // for cmp_ref (not used in file)
 
 #define LIST_ITERATE(list, node) for (ListNode *node = (list)->fst; node != NULL; node = node->nxt)
 
@@ -33,27 +34,27 @@ void list_ini(List *list);
        This function should be called before any other function is called on the list.
 */
 
-void *list_add(List *list, void *dat, Comparator cmp, Transformer func);
+bool list_add(List *list, void *key, void *dat, void *cmp, void *trans);
 /*
        Add an element to the list.
 
-       If an equal element is already on the list, return it and don't add anything.
-       Otherwise, return added element.
+       If an equal element is already in the list, don't add anything.
+       Return whether an element has been added.
 */
 
-void *list_get(List *list, void *key, Comparator cmp, Transformer func);
+void *list_get(List *list, void *key, void *cmp, void *trans);
 /*
        Get an element from the list.
 
        The first matching element is returned, or NULL if none found.
 */
 
-void *list_del(List *list, void *key, Comparator cmp, Transformer func);
+bool list_del(List *list, void *key, void *cmp, void *call, void *arg, void *trans);
 /*
-       Delete an element from the list.
+       Delete an element from the list if it is found.
+       Return whether an element has been deleted.
 
-       The first matching element is returned (after being removed from the list), or NULL
-               if none found.
+       The first matching element is deleted.
 */
 
 void list_apd(List *list, void *dat);
@@ -61,7 +62,12 @@ void list_apd(List *list, void *dat);
        Append an element at the end of the list.
 */
 
-ListNode **list_nfd(List *list, void *key, Comparator cmp);
+void list_ppd(List *list, void *dat);
+/*
+       Prepend an element at the start of the list.
+*/
+
+ListNode **list_nfd(List *list, void *key, void *cmp);
 /*
        Find the location of the first node matching key.
 
@@ -79,18 +85,18 @@ void list_nrm(List *list, ListNode **node);
        Remove the node at the given location.
 */
 
-void list_itr(List *list, Iterator func, void *arg);
+void list_itr(List *list, void *iter, void *arg, void *trans);
 /*
        Iterate over the list.
-       Calls func on every element, with the extra argument arg.
+       Calls iter on every element, with the extra argument arg.
 
        Note: the LIST_ITERATE macro can be used to do this without function calls.
 */
 
-void list_clr(List *list, Iterator func, void *arg);
+void list_clr(List *list, void *iter, void *arg, void *trans);
 /*
        Iterates over the list and deletes all elements.
-       Calls func on every element, with the extra argument arg.
+       Calls iter on every element, with the extra argument arg.
 
        The list is empty afterwards.
 */