From 2e781ef2c6956d9b4e11f08bdd23477c3b34ee2f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 10 Apr 2022 20:06:14 +0200 Subject: Fixed regression bug: cqueue_pop() did pop_back(), fixed to do pop_front(). Removed pop() functions in clist and cdeq as they are no standard. push() will push_back() for both. --- docs/cdeq_api.md | 1 - docs/clist_api.md | 4 ++-- examples/mapmap.c | 8 +++++--- include/stc/cdeq.h | 10 +++++----- include/stc/cqueue.h | 6 ++++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index 6749c5fd..1bc70bfa 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -54,7 +54,6 @@ cdeq_X_value* cdeq_X_push_back(cdeq_X* self, i_val value); cdeq_X_value* cdeq_X_push(cdeq_X* self, i_val value); // alias for push_back() cdeq_X_value* cdeq_X_emplace_back(cdeq_X* self, i_valraw raw); void cdeq_X_pop_back(cdeq_X* self); -void cdeq_X_pop(cdeq_X* self); // alias for pop_back() cdeq_X_iter cdeq_X_insert(cdeq_X* self, size_t idx, i_val value); // move value cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, size_t idx, const i_val[] arr, size_t n); // move arr values diff --git a/docs/clist_api.md b/docs/clist_api.md index c22d7bae..549cdd9f 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -54,8 +54,8 @@ void clist_X_push_front(clist_X* self, i_val value); void clist_X_emplace_front(clist_X* self, i_valraw raw); void clist_X_pop_front(clist_X* self); -void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back(). -void clist_X_push(clist_X* self, i_val value); // alias for push_back(). +void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back() +void clist_X_push(clist_X* self, i_val value); // alias for push_back() void clist_X_emplace_back(clist_X* self, i_valraw raw); clist_X_iter clist_X_insert_at(clist_X* self, clist_X_iter it, i_val value); // return iter to new elem diff --git a/examples/mapmap.c b/examples/mapmap.c index 2d681d23..0d6d2843 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -3,7 +3,7 @@ #define i_type People #define i_key_str #define i_val_str -#define i_keydrop(p) (printf("kdrop: %s\n", (p)->str), cstr_drop(p)) +#define i_keydrop(p) (printf("kdrop: %s\n", p->str), cstr_drop(p)) #include #define i_type Departments @@ -13,10 +13,12 @@ #define i_type Stack #define i_val_bind People_value -#define i_opt c_no_cmp +// Shorthand for: +//#define i_val People_value +//#define i_cmp People_value_cmp //#define i_from People_value_clone //#define i_drop People_value_drop -#include +#include void add(Departments* deps, const char* name, const char* email, const char* dep) { diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 5113af8c..c510b3e0 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -88,9 +88,7 @@ STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) {c_swap(_cx_se STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* pval) { return i_valto(pval); } -STC_INLINE void _cx_memb(_pop)(_cx_self* self) - { _cx_value* p = &self->data[--cdeq_rep_(self)->size]; i_valdrop(p); } -STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) +STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _i_queue { i_valdrop(self->data); ++self->data; --cdeq_rep_(self)->size; } STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + cdeq_rep_(self)->size - 1; } @@ -107,7 +105,9 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) STC_INLINE _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { return _cx_memb(_push)(self, value); } -STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_memb(_pop)(self); } + +STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) + { _cx_value* p = &self->data[--cdeq_rep_(self)->size]; i_valdrop(p); } STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, const size_t idx) { assert(idx < cdeq_rep_(self)->size); @@ -295,7 +295,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t n) { return n <= sz || _cx_memb(_expand_right_half_)(self, sz, n - sz); } -STC_DEF _cx_value* +STC_DEF _cx_value* // push back _cx_memb(_push)(_cx_self* self, i_val value) { struct cdeq_rep* r = cdeq_rep_(self); if (_cdeq_nfront(self) + r->size == r->cap) { diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h index aa3b8d2a..92cf4c49 100644 --- a/include/stc/cqueue.h +++ b/include/stc/cqueue.h @@ -57,5 +57,11 @@ int main() { #define _i_prefix cqueue_ #endif #define _i_queue +#define _emplace_back _emplace +#define _pop_front _pop + #include "cdeq.h" + +#undef _emplace_back +#undef _pop_front #undef _i_queue -- cgit v1.2.3