summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge <[email protected]>2020-04-19 17:07:03 +0200
committerTyge <[email protected]>2020-04-19 17:07:03 +0200
commit4c2688d482a34a58d6d54b9b4cd57d9d6656a509 (patch)
treed6d10739e0dca07d8dffa4739d586335bc733218
parent46c0760e960a19cd776c252d26cd51962d32e722 (diff)
downloadSTC-modified-4c2688d482a34a58d6d54b9b4cd57d9d6656a509.tar.gz
STC-modified-4c2688d482a34a58d6d54b9b4cd57d9d6656a509.zip
Refactored and changed name from pushAfter to insertAfter.
-rw-r--r--stc/clist.h29
1 files changed, 18 insertions, 11 deletions
diff --git a/stc/clist.h b/stc/clist.h
index 34858b86..13798318 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -64,28 +64,27 @@
\
static inline void \
clist_##tag##_pushFront(CList_##tag* self, Value value) { \
- _clist_pushAfter(tag, self->last, value); \
+ _clist_insertAfter(tag, self->last, value); \
if (!self->last) self->last = entry; \
} \
static inline void \
clist_##tag##_pushBack(CList_##tag* self, Value value) { \
- _clist_pushAfter(tag, self->last, value); \
+ _clist_insertAfter(tag, self->last, value); \
self->last = entry; \
} \
static inline void \
- clist_##tag##_pushAfter(CList_##tag* self, clist_##tag##_iter_t pos, Value value) { \
- _clist_pushAfter(tag, pos.item, value); \
+ clist_##tag##_insertAfter(CList_##tag* self, clist_##tag##_iter_t pos, Value value) { \
+ _clist_insertAfter(tag, pos.item, value); \
if (!self->last || pos.item == self->last) self->last = entry; \
} \
+ static inline void \
+ clist_##tag##_eraseAfter(CList_##tag* self, clist_##tag##_iter_t pos) { \
+ _clist_eraseAfter(tag, pos.item, valueDestroy); \
+ } \
\
static inline void \
clist_##tag##_popFront(CList_##tag* self) { \
- CListNode_##tag* del = self->last->next, *next = del->next; \
- --self->size; \
- if (next == del) self->last = NULL; \
- else self->last->next = next; \
- valueDestroy(&del->value); \
- free(del); \
+ _clist_eraseAfter(tag, self->last, valueDestroy); \
} \
\
static inline void \
@@ -127,7 +126,7 @@
typedef Value clist_##tag##_value_t
-#define _clist_pushAfter(tag, node, val) \
+#define _clist_insertAfter(tag, node, val) \
CListNode_##tag *entry = c_new_1(CListNode_##tag), \
*next = self->last ? node->next : entry; \
entry->value = val; \
@@ -135,6 +134,14 @@
++self->size; \
if (node) node->next = entry
+#define _clist_eraseAfter(tag, node, valueDestroy) \
+ CListNode_##tag* del = node->next, *next = del->next; \
+ node->next = next; \
+ if (--self->size == 0) self->last = NULL; \
+ else if (self->last == del) self->last = node; \
+ valueDestroy(&del->value); \
+ free(del)
+
declare_CListTypes(_i, int);