diff options
| author | Tyge Løvset <[email protected]> | 2022-05-03 02:04:55 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-03 02:04:55 +0200 |
| commit | 8536f3399973b5fde958367b3d3365cc4196de2e (patch) | |
| tree | d7cb09ef7020fc8f47e54e1afa6e96278dedb0d4 /include/stc/clist.h | |
| parent | 99fd3033e547775602d96cb676eb3b650006eae7 (diff) | |
| download | STC-modified-8536f3399973b5fde958367b3d3365cc4196de2e.tar.gz STC-modified-8536f3399973b5fde958367b3d3365cc4196de2e.zip | |
Added push front/back of existing nodes.
Diffstat (limited to 'include/stc/clist.h')
| -rw-r--r-- | include/stc/clist.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/stc/clist.h b/include/stc/clist.h index 818d3de3..d3a783a0 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -75,6 +75,11 @@ _c_clist_complete_types(clist_VOID, dummy); else entry->next = entry; \
entry->value = val
// +: set self->last based on node
+
+#define _c_clist_insert_node_after(self, _cx_self, node, entry) \
+ if (node) entry->next = node->next, node->next = entry; \
+ else entry->next = entry
+
#endif // CLIST_H_INCLUDED
#ifndef _i_prefix
@@ -217,12 +222,26 @@ _cx_memb(_push_back)(_cx_self* self, i_key value) { }
STC_DEF _cx_value*
+_cx_memb(_push_back_node)(_cx_self* self, _cx_node* node) {
+ _c_clist_insert_node_after(self, _cx_self, self->last, node);
+ self->last = node;
+ return &node->value;
+}
+
+STC_DEF _cx_value*
_cx_memb(_push_front)(_cx_self* self, i_key value) {
_c_clist_insert_after(self, _cx_self, self->last, value);
if (!self->last) self->last = entry;
return &entry->value;
}
+STC_DEF _cx_value*
+_cx_memb(_push_front_node)(_cx_self* self, _cx_node* node) {
+ _c_clist_insert_node_after(self, _cx_self, self->last, node);
+ if (!self->last) self->last = node;
+ return &node->value;
+}
+
STC_DEF _cx_iter
_cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value) {
_cx_node* node = it.ref ? it.prev : self->last;
|
