diff options
| author | Tyge <[email protected]> | 2020-04-20 17:27:25 +0200 |
|---|---|---|
| committer | Tyge <[email protected]> | 2020-04-20 17:27:25 +0200 |
| commit | 57fe842fde57b2855a8f51bf91fe2d6195c73376 (patch) | |
| tree | f2b7ccc6e2370d68cf7e9f50b4688b0ce09532b2 | |
| parent | 918d68b44354b38f45c796d2987b9e80a6566c3a (diff) | |
| download | STC-modified-57fe842fde57b2855a8f51bf91fe2d6195c73376.tar.gz STC-modified-57fe842fde57b2855a8f51bf91fe2d6195c73376.zip | |
Added remove and empty to cslist
| -rw-r--r-- | stc/cslist.h | 14 |
1 files changed, 14 insertions, 0 deletions
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) \ \ @@ -118,6 +119,19 @@ 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 |
