From 55c84dee6cce33e31a4ca3e0cdcbdbe85fcccac6 Mon Sep 17 00:00:00 2001 From: tylo Date: Mon, 31 Aug 2020 18:26:41 +0200 Subject: Fixed a few bugs. --- examples/list.c | 6 +++--- stc/clist.h | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/examples/list.c b/examples/list.c index 0da52c9b..fe81e5e2 100644 --- a/examples/list.c +++ b/examples/list.c @@ -28,9 +28,9 @@ int main() { puts(""); int removed = clist_fx_remove(&list, 30); - clist_fx_insert_after(&list, clist_fx_last(&list), 1000); - //clist_fx_insert_after(&list, clist_fx_before_begin(&list), 5); - clist_fx_push_front(&list, 5); + clist_fx_insert_after(&list, clist_fx_ahead(&list), 5); + clist_fx_insert_after(&list, clist_fx_last(&list), 500); + clist_fx_push_front(&list, 1964); c_foreach (i, clist_fx, list) printf(" %g", i.item->value); puts(""); diff --git a/stc/clist.h b/stc/clist.h index d17ddcec..e5dbf6f3 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -146,19 +146,22 @@ clist_##tag##_node_t *head = self->last ? self->last->next : NULL; \ clist_##tag##_iter_t it = {head, NULL, &self->last}; return it; \ } \ - STC_INLINE void \ - clist_##tag##_next(clist_##tag##_iter_t* it) { \ - if (it->item == *it->_last) it->end = it->item = it->item->next; \ - else it->item = it->item->next; \ - } \ STC_INLINE clist_##tag##_iter_t \ clist_##tag##_before_begin(clist_##tag* self) { \ clist_##tag##_iter_t it = {self->last, self->last, &self->last}; return it; \ } \ + STC_INLINE clist_##tag##_iter_t \ + clist_##tag##_ahead(clist_##tag* self) {return clist_##tag##_before_begin(self);} \ + \ STC_INLINE clist_##tag##_iter_t \ clist_##tag##_last(clist_##tag* self) { \ clist_##tag##_iter_t it = {self->last, NULL, &self->last}; return it; \ } \ + STC_INLINE void \ + clist_##tag##_next(clist_##tag##_iter_t* it) { \ + if (it->item == *it->_last) it->end = it->item = it->item->next; \ + else it->item = it->item->next; \ + } \ \ implement_clist_7(tag, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw) \ typedef Value clist_##tag##_value_t @@ -197,7 +200,7 @@ STC_API clist_##tag##_iter_t \ clist_##tag##_insert_after_v(clist_##tag* self, clist_##tag##_iter_t pos, Value value) { \ _clist_insert_after(self, tag, pos.item, value); \ - if (pos.item != pos.end) self->last = entry; \ + if (pos.item == self->last && pos.item != pos.end) self->last = entry; \ pos.item = entry; return pos; \ } \ STC_API clist_##tag##_iter_t \ @@ -273,7 +276,7 @@ _clist_splice_after(clist_void* self, clist_void_iter_t pos, clist_void* other) clist_void_node_t *next = pos.item->next; pos.item->next = other->last->next; other->last->next = next; - if (pos.item == pos.end) self->last = other->last; + if (pos.item == self->last && pos.item != pos.end) self->last = other->last; } other->last = NULL; } -- cgit v1.2.3