From 57fe842fde57b2855a8f51bf91fe2d6195c73376 Mon Sep 17 00:00:00 2001 From: Tyge Date: Mon, 20 Apr 2020 17:27:25 +0200 Subject: Added remove and empty to cslist --- stc/cslist.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/stc/cslist.h b/stc/cslist.h index dd321f00..e8743cd2 100644 --- a/stc/cslist.h +++ b/stc/cslist.h @@ -58,6 +58,7 @@ #define cslist_init {NULL} #define cslist_front(list) (list).last->next->value #define cslist_back(list) (list).last->value +#define cslist_empty(list) ((list).last == NULL) #define declare_CSList_6(tag, Value, valueDestroy, valueCompare, ValueRaw, valueGetRaw) \ \ @@ -117,6 +118,19 @@ it.item = it.item == *it._last ? NULL : it.item->next; \ return it; \ } \ + \ + static inline int \ + cslist_##tag##_remove(CSList_##tag* self, ValueRaw val) { \ + cslist_##tag##_iter_t prev = {self->last}; int n = 0; \ + c_foreach (i, cslist_##tag, *self) { \ + if (valueCompare(valueGetRaw(&i.item->value), &val) == 0) { \ + cslist_##tag##_eraseAfter(self, prev), ++n; \ + if (prev.item == i.item) break; \ + } \ + prev = i; \ + } \ + return n; \ + } \ \ typedef Value cslist_##tag##_value_t -- cgit v1.2.3