summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge <[email protected]>2020-04-20 21:44:47 +0200
committerTyge <[email protected]>2020-04-20 21:44:47 +0200
commite49a38337de57122dd379f88abe2c6656d07f2cd (patch)
tree9339b0557563a45e7497db476d8f0bd5e82ec52d
parent57fe842fde57b2855a8f51bf91fe2d6195c73376 (diff)
downloadSTC-modified-e49a38337de57122dd379f88abe2c6656d07f2cd.tar.gz
STC-modified-e49a38337de57122dd379f88abe2c6656d07f2cd.zip
Added splice
-rw-r--r--stc/cslist.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/stc/cslist.h b/stc/cslist.h
index e8743cd2..9c1814f3 100644
--- a/stc/cslist.h
+++ b/stc/cslist.h
@@ -79,6 +79,7 @@
_cslist_insertAfter(tag, pos.item, value); \
if (!self->last || pos.item == self->last) self->last = entry; \
} \
+ \
static inline void \
cslist_##tag##_eraseAfter(CSList_##tag* self, cslist_##tag##_iter_t pos) { \
_cslist_eraseAfter(tag, pos.item, valueDestroy); \
@@ -112,6 +113,10 @@
CSListNode_##tag *head = lst->last ? lst->last->next : NULL; \
return (cslist_##tag##_iter_t) {head, &lst->last}; \
} \
+ static inline cslist_##tag##_iter_t \
+ cslist_##tag##_last(CSList_##tag* lst) { \
+ return (cslist_##tag##_iter_t) {lst->last, &lst->last}; \
+ } \
\
static inline cslist_##tag##_iter_t \
cslist_##tag##_next(cslist_##tag##_iter_t it) { \
@@ -119,6 +124,27 @@
return it; \
} \
\
+ static inline void \
+ _cslist_##tag##_splice(CSList_##tag* self, cslist_##tag##_iter_t pos, CSList_##tag* other, bool bottom) { \
+ if (!pos.item) \
+ self->last = pos.item = other->last; \
+ else if (other->last) { \
+ CSListNode_##tag *next = pos.item->next; \
+ pos.item->next = other->last->next; \
+ other->last->next = next; \
+ if (bottom && pos.item == self->last) self->last = other->last; \
+ } \
+ other->last = NULL; \
+ } \
+ static inline void \
+ cslist_##tag##_spliceFront(CSList_##tag* self, CSList_##tag* other) { \
+ _cslist_##tag##_splice(self, cslist_##tag##_last(self), other, false); \
+ } \
+ static inline void \
+ cslist_##tag##_spliceAfter(CSList_##tag* self, cslist_##tag##_iter_t pos, CSList_##tag* other) { \
+ _cslist_##tag##_splice(self, pos, other, true); \
+ } \
+ \
static inline int \
cslist_##tag##_remove(CSList_##tag* self, ValueRaw val) { \
cslist_##tag##_iter_t prev = {self->last}; int n = 0; \