From 8536f3399973b5fde958367b3d3365cc4196de2e Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 3 May 2022 02:04:55 +0200 Subject: Added push front/back of existing nodes. --- include/stc/clist.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/stc/clist.h') 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 @@ -216,6 +221,13 @@ _cx_memb(_push_back)(_cx_self* self, i_key value) { return &entry->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); @@ -223,6 +235,13 @@ _cx_memb(_push_front)(_cx_self* self, i_key value) { 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; -- cgit v1.2.3