From 9aee8dedd48f5ac278eb838d8ebf3f669e541283 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 11 Sep 2020 13:14:30 +0200 Subject: Added back clist_last() and some internal renames. --- stc/clist.h | 21 ++++++++++++--------- stc/cvec.h | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/stc/clist.h b/stc/clist.h index acffba6a..de3b3f75 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -143,11 +143,15 @@ STC_API size_t _clist_size(const clist_void* self); STC_INLINE clist_##X##_iter_t \ clist_##X##_begin(const clist_##X* self) { \ clist_##X##_node_t* head = self->last ? self->last->next : NULL; \ - clist_##X##_iter_t it = {&self->last, head}; return it; \ + clist_##X##_iter_t it = {&self->last, head, 0}; return it; \ + } \ + STC_INLINE clist_##X##_iter_t \ + clist_##X##_last(const clist_##X* self) { \ + clist_##X##_iter_t it = {&self->last, self->last, 0}; return it; \ } \ STC_INLINE clist_##X##_iter_t \ clist_##X##_end(const clist_##X* self) { \ - clist_##X##_iter_t it = {NULL}; return it; \ + clist_##X##_iter_t it = {NULL, NULL}; return it; \ } \ STC_INLINE void \ clist_##X##_next(clist_##X##_iter_t* it) { \ @@ -165,8 +169,8 @@ STC_API size_t _clist_size(const clist_void* self); STC_API clist_##X##_iter_t \ clist_##X##_erase_after(clist_##X* self, clist_##X##_iter_t pos); \ STC_INLINE clist_##X##_iter_t \ - clist_##X##_erase_range_after(clist_##X* self, clist_##X##_iter_t pos, clist_##X##_iter_t last) { \ - while (pos.item != last.item) pos = clist_##X##_erase_after(self, pos); \ + clist_##X##_erase_range_after(clist_##X* self, clist_##X##_iter_t pos, clist_##X##_iter_t finish) { \ + while (pos.item != finish.item) pos = clist_##X##_erase_after(self, pos); \ return pos; \ } \ \ @@ -180,12 +184,11 @@ STC_API size_t _clist_size(const clist_void* self); } \ STC_INLINE void \ clist_##X##_splice_back(clist_##X* self, clist_##X* other) { \ - clist_##X##_iter_t last = {&self->last, self->last, 0}; \ - clist_##X##_splice_after(self, last, other); \ + clist_##X##_splice_after(self, clist_##X##_last(self), other); \ } \ \ STC_API clist_##X##_iter_t \ - clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t last, RawValue val); \ + clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish, RawValue val); \ STC_API clist_##X##_iter_t \ clist_##X##_find(const clist_##X* self, RawValue val); \ STC_API size_t \ @@ -244,9 +247,9 @@ STC_API size_t _clist_size(const clist_void* self); } \ \ STC_API clist_##X##_iter_t \ - clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t last, RawValue val) { \ + clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish, RawValue val) { \ clist_##X##_iter_t i = first; \ - for (clist_##X##_next(&i); i.item != last.item; clist_##X##_next(&i)) { \ + for (clist_##X##_next(&i); i.item != finish.item; clist_##X##_next(&i)) { \ RawValue r = valueToRaw(&i.item->value); \ if (valueCompareRaw(&r, &val) == 0) return first; \ first = i; \ diff --git a/stc/cvec.h b/stc/cvec.h index 62c1c817..1c7c245c 100644 --- a/stc/cvec.h +++ b/stc/cvec.h @@ -99,22 +99,22 @@ } \ \ STC_API cvec_##X##_iter_t \ - cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t last); \ + cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t finish); \ \ STC_INLINE cvec_##X##_iter_t \ - cvec_##X##_insert_range_ptr(cvec_##X* self, size_t idx, Value* pfirst, Value* plast) { \ - cvec_##X##_iter_t pos = {self->data + idx}, first = {pfirst}, last = {plast}; \ - return cvec_##X##_insert_range(self, pos, first, last); \ + cvec_##X##_insert_range_ptr(cvec_##X* self, size_t idx, Value* pfirst, Value* pfinish) { \ + cvec_##X##_iter_t pos = {self->data + idx}, first = {pfirst}, finish = {pfinish}; \ + return cvec_##X##_insert_range(self, pos, first, finish); \ } \ STC_INLINE cvec_##X##_iter_t \ cvec_##X##_insert(cvec_##X* self, cvec_##X##_iter_t pos, Value value) { \ - cvec_##X##_iter_t first = {&value}, last = {&value + 1}; \ - return cvec_##X##_insert_range(self, pos, first, last); \ + cvec_##X##_iter_t first = {&value}, finish = {&value + 1}; \ + return cvec_##X##_insert_range(self, pos, first, finish); \ } \ STC_INLINE cvec_##X##_iter_t \ cvec_##X##_insert_at_idx(cvec_##X* self, size_t idx, Value value) { \ - cvec_##X##_iter_t pos = {self->data + idx}, first = {&value}, last = {&value + 1}; \ - return cvec_##X##_insert_range(self, pos, first, last); \ + cvec_##X##_iter_t pos = {self->data + idx}, first = {&value}, finish = {&value + 1}; \ + return cvec_##X##_insert_range(self, pos, first, finish); \ } \ STC_INLINE cvec_##X##_iter_t \ cvec_##X##_emplace(cvec_##X* self, cvec_##X##_iter_t pos, RawValue rawValue) { \ @@ -126,7 +126,7 @@ } \ \ STC_API cvec_##X##_iter_t \ - cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t last); \ + cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish); \ \ STC_INLINE cvec_##X##_iter_t \ cvec_##X##_erase(cvec_##X* self, cvec_##X##_iter_t pos) { \ @@ -135,19 +135,19 @@ } \ STC_INLINE cvec_##X##_iter_t \ cvec_##X##_erase_at_idx(cvec_##X* self, size_t idx) { \ - cvec_##X##_iter_t first = {self->data + idx}, last = {first.item + 1}; \ - return cvec_##X##_erase_range(self, first, last); \ + cvec_##X##_iter_t first = {self->data + idx}, finish = {first.item + 1}; \ + return cvec_##X##_erase_range(self, first, finish); \ } \ STC_INLINE cvec_##X##_iter_t \ - cvec_##X##_erase_range_idx(cvec_##X* self, size_t ifirst, size_t ilast) { \ - cvec_##X##_iter_t first = {self->data + ifirst}, last = {self->data + ilast}; \ - return cvec_##X##_erase_range(self, first, last); \ + cvec_##X##_erase_range_idx(cvec_##X* self, size_t ifirst, size_t ifinish) { \ + cvec_##X##_iter_t first = {self->data + ifirst}, finish = {self->data + ifinish}; \ + return cvec_##X##_erase_range(self, first, finish); \ } \ \ STC_API cvec_##X##_iter_t \ cvec_##X##_find(const cvec_##X* self, RawValue rawValue); \ STC_API cvec_##X##_iter_t \ - cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t last, RawValue rawValue); \ + cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish, RawValue rawValue); \ \ STC_INLINE Value* \ cvec_##X##_front(cvec_##X* self) {return self->data;} \ @@ -163,8 +163,8 @@ STC_API int \ cvec_##X##_value_compare(const Value* x, const Value* y); \ STC_INLINE void \ - cvec_##X##_sort_with(cvec_##X* self, size_t ifirst, size_t ilast, int(*cmp)(const Value*, const Value*)) { \ - qsort(self->data + ifirst, ilast - ifirst, sizeof(Value), (_cvec_cmp) cmp); \ + cvec_##X##_sort_with(cvec_##X* self, size_t ifirst, size_t ifinish, int(*cmp)(const Value*, const Value*)) { \ + qsort(self->data + ifirst, ifinish - ifirst, sizeof(Value), (_cvec_cmp) cmp); \ } \ STC_INLINE void \ cvec_##X##_sort(cvec_##X* self) { \ @@ -239,9 +239,9 @@ } \ \ STC_API cvec_##X##_iter_t \ - cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t last) { \ + cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t finish) { \ enum {max_buf = c_max_alloca / sizeof(Value) + 1}; Value buf[max_buf]; \ - size_t len = last.item - first.item, idx = pos.item - self->data, size = cvec_size(*self); \ + size_t len = finish.item - first.item, idx = pos.item - self->data, size = cvec_size(*self); \ Value* xbuf = (Value *) memcpy(len > max_buf ? c_new_n(Value, len) : buf, first.item, len * sizeof(Value)); \ if (size + len > cvec_capacity(*self)) \ cvec_##X##_reserve(self, 4 + (size + len) * 3 / 2); \ @@ -254,20 +254,20 @@ } \ \ STC_API cvec_##X##_iter_t \ - cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t last) { \ - intptr_t len = last.item - first.item; \ + cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish) { \ + intptr_t len = finish.item - first.item; \ if (len > 0) { \ Value* p = first.item, *end = p + _cvec_size(self); \ - while (p != last.item) valueDestroy(p++); \ - memmove(first.item, last.item, (end - last.item) * sizeof(Value)); \ + while (p != finish.item) valueDestroy(p++); \ + memmove(first.item, finish.item, (end - finish.item) * sizeof(Value)); \ _cvec_size(self) -= len; \ } \ return first; \ } \ \ STC_API cvec_##X##_iter_t \ - cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t last, RawValue rawValue) { \ - for (; first.item != last.item; cvec_##X##_next(&first)) { \ + cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish, RawValue rawValue) { \ + for (; first.item != finish.item; cvec_##X##_next(&first)) { \ RawValue r = valueToRaw(first.item); \ if (valueCompareRaw(&r, &rawValue) == 0) return first; \ } \ -- cgit v1.2.3