From 90624d6d398ff1d0f79df3dd656c4ad0c9c498a9 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 9 Aug 2022 17:34:13 +0200 Subject: Experiment with other type of iterator. Does not compile. --- include/stc/cstack.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/stc/cstack.h') diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 46d209ca..3986e366 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -170,12 +170,12 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) #endif // !_i_no_clone STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter){(_cx_value*)self->data}; } + { return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->size}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){(_cx_value*)self->data + self->size}; } + { return c_make(_cx_iter){NULL}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) { it.ref += offs; return it; } -- cgit v1.2.3 From 1756309078f4c09765bde898e50b8a3078cebc7d Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 10 Aug 2022 12:59:20 +0200 Subject: Fixed cdeq, cvec, cmap and cstack: iterators .ref is now NULL when it is end(). clist and csmap/cset already has this property. --- include/stc/cdeq.h | 54 +++++++++++++++++++++------------------------------ include/stc/cmap.h | 35 +++++++++++++++++---------------- include/stc/cstack.h | 6 +++--- include/stc/cvec.h | 40 +++++++++++++++++++------------------- include/stc/forward.h | 2 +- 5 files changed, 64 insertions(+), 73 deletions(-) (limited to 'include/stc/cstack.h') diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index c5e08393..da7f258f 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -95,10 +95,10 @@ STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { return c_make(_cx_iter){self->data}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){self->data + cdeq_rep_(self)->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) - { it.ref += offs; return it; } + { return c_make(_cx_iter){NULL, self->data + cdeq_rep_(self)->size}; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) + { if ((it.ref += offs) >= it._end) it.ref = NULL; return it; } #if !defined _i_queue @@ -127,7 +127,7 @@ _cx_memb(_insert_n)(_cx_self* self, const size_t idx, const _cx_value arr[], con } STC_INLINE _cx_value* _cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value) { - return _cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1); + return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it._end), &value, &value + 1); } STC_INLINE _cx_iter @@ -139,16 +139,10 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { return _cx_memb(_erase_range_p)(self, it.ref, it.ref + 1); } STC_INLINE _cx_iter -_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { - return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); +_cx_memb(_erase_range)(_cx_self* self, _cx_iter i1, _cx_iter i2) { + return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2._end)); } -#if !defined _i_no_clone -STC_INLINE _cx_value* -_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { - return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref); -} -#endif // !_i_no_clone #if !defined _i_no_emplace STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, _cx_raw raw) { @@ -165,7 +159,7 @@ _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], cons } STC_INLINE _cx_value* _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, _cx_raw raw) { - return _cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1); + return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it._end), &raw, &raw + 1); } #endif // !_i_no_emplace @@ -178,9 +172,7 @@ _cx_memb(_find)(const _cx_self* self, _cx_raw raw) { STC_INLINE const _cx_value* _cx_memb(_get)(const _cx_self* self, _cx_raw raw) { - _cx_iter end = _cx_memb(_end)(self); - _cx_value* val = _cx_memb(_find_in)(_cx_memb(_begin)(self), end, raw).ref; - return val == end.ref ? NULL : val; + return _cx_memb(_find_in)(_cx_memb(_begin)(self), _cx_memb(_end)(self), raw).ref; } STC_INLINE _cx_value* @@ -188,9 +180,9 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw) { return (_cx_value *) _cx_memb(_get)(self, raw); } STC_INLINE void -_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, - int(*_cmp_)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, i2.ref - i1.ref, sizeof *i1.ref, (int(*)(const void*, const void*)) _cmp_); +_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { + qsort(i1.ref, (i2.ref ? i2.ref : i2._end) - i1.ref, sizeof *i1.ref, + (int(*)(const void*, const void*)) cmp); } STC_INLINE void @@ -379,16 +371,13 @@ _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos, STC_DEF _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { - const size_t n = p2 - p1; - if (n > 0) { - _cx_value* p = p1, *end = self->data + cdeq_rep_(self)->size; - for (; p != p2; ++p) { i_keydrop(p); } - if (p1 == self->data) - self->data += n; - else memmove(p1, p2, (end - p2) * sizeof(i_key)); - cdeq_rep_(self)->size -= n; - } - return c_make(_cx_iter){p1}; + intptr_t len = p2 - p1; + _cx_value* p = p1, *end = self->data + cdeq_rep_(self)->size; + for (; p != p2; ++p) + { i_keydrop(p); } + memmove(p1, p2, (end - p2) * sizeof *p1); + cdeq_rep_(self)->size -= len; + return c_make(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined _i_no_emplace @@ -418,8 +407,9 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { - for (; i1.ref != i2.ref; ++i1.ref) { - _cx_raw r = i_keyto(i1.ref); + const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + for (; i1.ref != p2; ++i1.ref) { + const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) return i1; } diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 1394b3a7..0d1c13d9 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -188,11 +188,28 @@ _cx_memb(_push)(_cx_self* self, _cx_value _val) { return _res; } + +STC_INLINE _cx_iter +_cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){NULL}; } + +STC_INLINE void +_cx_memb(_next)(_cx_iter* it) { + while ((++it->ref, *++it->_hx == 0)) ; + if (it->ref == it->_end) it->ref = NULL; +} + +STC_INLINE _cx_iter +_cx_memb(_advance)(_cx_iter it, size_t n) { + while (n-- && it.ref) _cx_memb(_next)(&it); + return it; +} + STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { i_size idx; if (!(self->size && self->_hashx[idx = _cx_memb(_bucket_)(self, &rkey).idx])) - return c_make(_cx_iter){NULL}; + return _cx_memb(_end)(self); return c_make(_cx_iter){self->table+idx, self->table+self->bucket_count, self->_hashx+idx}; } @@ -218,22 +235,6 @@ _cx_memb(_begin)(const _cx_self* self) { return it; } -STC_INLINE _cx_iter -_cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){NULL}; } - -STC_INLINE void -_cx_memb(_next)(_cx_iter* it) { - while ((++it->ref, *++it->_hx == 0)) ; - if (it->ref == it->_end) it->ref = NULL; -} - -STC_INLINE _cx_iter -_cx_memb(_advance)(_cx_iter it, size_t n) { - while (n-- && it.ref) _cx_memb(_next)(&it); - return it; -} - STC_INLINE size_t _cx_memb(_erase)(_cx_self* self, _cx_rawkey rkey) { if (self->size == 0) diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 3986e366..811479c4 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -173,11 +173,11 @@ STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->size}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){NULL}; } + { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->size}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, intptr_t offs) - { it.ref += offs; return it; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) + { if ((it.ref += offs) >= it._end) it.ref = NULL ; return it; } #include "template.h" diff --git a/include/stc/cvec.h b/include/stc/cvec.h index a4308628..99df920c 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -106,7 +106,7 @@ _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], cons } STC_INLINE _cx_value* _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, _cx_raw raw) { - return _cx_memb(_emplace_range_p)(self, it.ref, &raw, &raw + 1); + return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it._end), &raw, &raw + 1); } #endif // !_i_no_emplace @@ -121,10 +121,6 @@ STC_INLINE void _cx_memb(_copy)(_cx_self* self, const _cx_self* other) { _cx_memb(_drop)(self); *self = _cx_memb(_clone)(*other); } -STC_INLINE _cx_value* -_cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { - return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref); -} #endif // !_i_no_clone STC_INLINE size_t _cx_memb(_size)(const _cx_self* cx) { return cvec_rep_(cx)->size; } @@ -142,7 +138,8 @@ STC_INLINE _cx_value* _cx_memb(_push_back)(_cx_self* self, i_key value) STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_memb(_pop)(self); } STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { size_t n = cvec_rep_(self)->size; return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; } -STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){NULL, self->data + cvec_rep_(self)->size}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) { if ((it.ref += offs) >= it._end) it.ref = NULL; return it; } @@ -182,7 +179,7 @@ _cx_memb(_insert_n)(_cx_self* self, const size_t idx, const _cx_value arr[], con } STC_INLINE _cx_value* _cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value) { - return _cx_memb(_insert_range_p)(self, it.ref, &value, &value + 1); + return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it._end), &value, &value + 1); } STC_INLINE _cx_iter @@ -194,8 +191,8 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { return _cx_memb(_erase_range_p)(self, it.ref, it.ref + 1); } STC_INLINE _cx_iter -_cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { - return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); +_cx_memb(_erase_range)(_cx_self* self, _cx_iter i1, _cx_iter i2) { + return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2._end)); } STC_INLINE const _cx_value* @@ -237,10 +234,11 @@ _cx_memb(_lower_bound)(const _cx_self* self, _cx_raw raw) { } STC_INLINE void -_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, - int(*_cmp_)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, i2.ref - i1.ref, sizeof(_cx_value), (int(*)(const void*, const void*)) _cmp_); +_cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { + qsort(i1.ref, (i2.ref ? i2.ref : i2._end) - i1.ref, sizeof(_cx_value), + (int(*)(const void*, const void*)) cmp); } + STC_INLINE void _cx_memb(_sort)(_cx_self* self) { _cx_memb(_sort_range)(_cx_memb(_begin)(self), _cx_memb(_end)(self), _cx_memb(_value_cmp)); @@ -356,7 +354,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { { i_keydrop(p); } memmove(p1, p2, (end - p2) * sizeof *p1); cvec_rep_(self)->size -= len; - return c_make(_cx_iter){.ref = p2 == end ? NULL : p1, end - len}; + return c_make(_cx_iter){p2 == end ? NULL : p1, end - len}; } #if !defined _i_no_clone @@ -395,7 +393,8 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, #if !c_option(c_no_cmp) STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { - for (; i1.ref != i2.ref; ++i1.ref) { + const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + for (; i1.ref != p2; ++i1.ref) { const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) return i1; @@ -405,18 +404,19 @@ _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { STC_DEF _cx_iter _cx_memb(_binary_search_in)(_cx_iter i1, _cx_iter i2, const _cx_raw raw, _cx_iter* lower_bound) { - _cx_iter mid, last = i2; - while (i1.ref != i2.ref) { - mid.ref = i1.ref + (i2.ref - i1.ref)/2; + const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + _cx_iter mid = i1; + while (i1.ref != p2) { + mid.ref = i1.ref + (p2 - i1.ref)/2; const _cx_raw m = i_keyto(mid.ref); const int c = i_cmp((&raw), (&m)); if (!c) return *lower_bound = mid; - else if (c < 0) i2.ref = mid.ref; + else if (c < 0) p2 = mid.ref; else i1.ref = mid.ref + 1; } - *lower_bound = i1; - return last; + *lower_bound = i1.ref == i2._end ? i2 : i1; + return i2; } STC_DEF int diff --git a/include/stc/forward.h b/include/stc/forward.h index 1a85f1ed..9be399af 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -194,7 +194,7 @@ typedef union { #define _c_cstack_fixed(SELF, VAL, CAP) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ typedef struct SELF { \ SELF##_value data[CAP]; \ size_t size; \ -- cgit v1.2.3 From 35f63cb6d76f47a00daa5929808d75f715566657 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Thu, 11 Aug 2022 00:05:39 +0200 Subject: Code formatting only. --- include/stc/carr2.h | 11 +++++++---- include/stc/carr3.h | 11 +++++++---- include/stc/cdeq.h | 22 +++++++++++++++------- include/stc/clist.h | 5 ++--- include/stc/cstack.h | 13 ++++++++----- include/stc/cvec.h | 26 ++++++++++++++++++-------- 6 files changed, 57 insertions(+), 31 deletions(-) (limited to 'include/stc/cstack.h') diff --git a/include/stc/carr2.h b/include/stc/carr2.h index f15c6034..1762b8ad 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -88,14 +88,17 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y) { return self->ydim*x + y; } -STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { size_t n = self->xdim*self->ydim; return c_make(_cx_iter){n ? *self->data : NULL, *self->data + n}; } + +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { + size_t n = self->xdim*self->ydim; + return c_make(_cx_iter){n ? *self->data : NULL, *self->data + n}; +} STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } - +STC_INLINE void _cx_memb(_next)(_cx_iter* it) + { if (++it->ref == it->_end) it->ref = NULL; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/carr3.h b/include/stc/carr3.h index ec67645c..4de21208 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -91,14 +91,17 @@ STC_INLINE size_t _cx_memb(_idx)(const _cx_self* self, size_t x, size_t y, size_ return self->zdim*(self->ydim*x + y) + z; } -STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { size_t n = _cx_memb(_size)(self); return c_make(_cx_iter){n ? **self->data : NULL, **self->data + n}; } + +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { + size_t n = _cx_memb(_size)(self); + return c_make(_cx_iter){n ? **self->data : NULL, **self->data + n}; +} STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } - +STC_INLINE void _cx_memb(_next)(_cx_iter* it) + { if (++it->ref == it->_end) it->ref = NULL; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index d08e0155..644af838 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -92,13 +92,6 @@ STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + cdeq_rep_(self)->size - 1; } STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _i_queue { i_keydrop(self->data); ++self->data; --cdeq_rep_(self)->size; } -STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { size_t n = cdeq_rep_(self)->size; return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; } -STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){NULL, self->data + cdeq_rep_(self)->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) - { if ((it.ref += offs) >= it._end) it.ref = NULL; return it; } #if !defined _i_queue @@ -143,6 +136,21 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter i1, _cx_iter i2) { return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2._end)); } + +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { + size_t n = cdeq_rep_(self)->size; + return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; +} + +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){NULL, self->data + cdeq_rep_(self)->size}; } + +STC_INLINE void _cx_memb(_next)(_cx_iter* it) + { if (++it->ref == it->_end) it->ref = NULL; } + +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) + { if ((it.ref += n) >= it._end) it.ref = NULL; return it; } + #if !defined _i_no_emplace STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, _cx_raw raw) { diff --git a/include/stc/clist.h b/include/stc/clist.h index 229db32c..5b9cf0d3 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -159,9 +159,8 @@ _cx_memb(_begin)(const _cx_self* self) { } STC_INLINE _cx_iter -_cx_memb(_end)(const _cx_self* self) { - return c_make(_cx_iter){NULL}; -} +_cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){NULL}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) { diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 811479c4..a524b71c 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -169,15 +169,18 @@ STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) { return i_keyto(val); } #endif // !_i_no_clone -STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->size}; } +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { + return c_make(_cx_iter){self->size ? (_cx_value*)self->data : NULL, + (_cx_value*)self->data + self->size}; +} STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } +STC_INLINE void _cx_memb(_next)(_cx_iter* it) + { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) - { if ((it.ref += offs) >= it._end) it.ref = NULL ; return it; } +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) + { if ((it.ref += n) >= it._end) it.ref = NULL ; return it; } #include "template.h" diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 99df920c..a457c3dc 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -136,14 +136,6 @@ STC_INLINE void _cx_memb(_pop)(_cx_self* self) STC_INLINE _cx_value* _cx_memb(_push_back)(_cx_self* self, i_key value) { return _cx_memb(_push)(self, value); } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_memb(_pop)(self); } -STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) - { size_t n = cvec_rep_(self)->size; return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; } -STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) - { return c_make(_cx_iter){NULL, self->data + cvec_rep_(self)->size}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; } -STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t offs) - { if ((it.ref += offs) >= it._end) it.ref = NULL; return it; } -STC_INLINE size_t _cx_memb(_index)(const _cx_self* cx, _cx_iter it) { return it.ref - cx->data; } STC_INLINE _cx_self _cx_memb(_with_size)(const size_t size, i_key null) { @@ -204,6 +196,24 @@ _cx_memb(_at_mut)(_cx_self* self, const size_t idx) { assert(idx < cvec_rep_(self)->size); return self->data + idx; } + +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { + size_t n = cvec_rep_(self)->size; + return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; +} + +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_make(_cx_iter){NULL, self->data + cvec_rep_(self)->size}; } + +STC_INLINE void _cx_memb(_next)(_cx_iter* it) + { if (++it->ref == it->_end) it->ref = NULL; } + +STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) + { if ((it.ref += n) >= it._end) it.ref = NULL; return it; } + +STC_INLINE size_t _cx_memb(_index)(const _cx_self* cx, _cx_iter it) + { return it.ref - cx->data; } + #if !c_option(c_no_cmp) STC_INLINE _cx_iter -- cgit v1.2.3 From 65199590def8459198f9460c5d975a1df22d00a8 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Thu, 11 Aug 2022 08:31:53 +0200 Subject: Renamed all iter members ._end to .end, to make them "public". --- include/stc/carr2.h | 2 +- include/stc/carr3.h | 2 +- include/stc/cdeq.h | 14 +++++++------- include/stc/cmap.h | 4 ++-- include/stc/cstack.h | 4 ++-- include/stc/cstr.h | 2 +- include/stc/csview.h | 2 +- include/stc/cvec.h | 18 +++++++++--------- include/stc/forward.h | 16 ++++++++-------- 9 files changed, 32 insertions(+), 32 deletions(-) (limited to 'include/stc/cstack.h') diff --git a/include/stc/carr2.h b/include/stc/carr2.h index 1762b8ad..f55cdd17 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -98,7 +98,7 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, *self->data + self->xdim*self->ydim}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { if (++it->ref == it->_end) it->ref = NULL; } + { if (++it->ref == it->end) it->ref = NULL; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 4de21208..fdc29b6f 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -101,7 +101,7 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, **self->data + _cx_memb(_size)(self)}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { if (++it->ref == it->_end) it->ref = NULL; } + { if (++it->ref == it->end) it->ref = NULL; } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 179959fd..d3c7fede 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -120,7 +120,7 @@ _cx_memb(_insert_n)(_cx_self* self, const size_t idx, const _cx_value arr[], con } STC_INLINE _cx_iter _cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value) { - return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it._end), &value, &value + 1); + return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it.end), &value, &value + 1); } STC_INLINE _cx_iter @@ -133,7 +133,7 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { } STC_INLINE _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter i1, _cx_iter i2) { - return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2._end)); + return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2.end)); } @@ -146,10 +146,10 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, self->data + cdeq_rep_(self)->size}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { if (++it->ref == it->_end) it->ref = NULL; } + { if (++it->ref == it->end) it->ref = NULL; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) - { if ((it.ref += n) >= it._end) it.ref = NULL; return it; } + { if ((it.ref += n) >= it.end) it.ref = NULL; return it; } #if !defined _i_no_emplace STC_INLINE _cx_value* @@ -167,7 +167,7 @@ _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], cons } STC_INLINE _cx_iter _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, _cx_raw raw) { - return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it._end), &raw, &raw + 1); + return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it.end), &raw, &raw + 1); } #endif // !_i_no_emplace @@ -189,7 +189,7 @@ _cx_memb(_get_mut)(_cx_self* self, _cx_raw raw) STC_INLINE void _cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, (i2.ref ? i2.ref : i2._end) - i1.ref, sizeof *i1.ref, + qsort(i1.ref, (i2.ref ? i2.ref : i2.end) - i1.ref, sizeof *i1.ref, (int(*)(const void*, const void*)) cmp); } @@ -416,7 +416,7 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { - const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + const _cx_value* p2 = i2.ref ? i2.ref : i2.end; for (; i1.ref != p2; ++i1.ref) { const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 0d1c13d9..971d00a8 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -196,7 +196,7 @@ _cx_memb(_end)(const _cx_self* self) STC_INLINE void _cx_memb(_next)(_cx_iter* it) { while ((++it->ref, *++it->_hx == 0)) ; - if (it->ref == it->_end) it->ref = NULL; + if (it->ref == it->end) it->ref = NULL; } STC_INLINE _cx_iter @@ -231,7 +231,7 @@ _cx_memb(_begin)(const _cx_self* self) { if (it._hx) while (*it._hx == 0) ++it.ref, ++it._hx; - if (it.ref == it._end) it.ref = NULL; + if (it.ref == it.end) it.ref = NULL; return it; } diff --git a/include/stc/cstack.h b/include/stc/cstack.h index a524b71c..e1839d37 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -178,9 +178,9 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, (_cx_value*)self->data + self->size}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { if (++it->ref == it->_end) it->ref = NULL; } + { if (++it->ref == it->end) it->ref = NULL; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) - { if ((it.ref += n) >= it._end) it.ref = NULL ; return it; } + { if ((it.ref += n) >= it.end) it.ref = NULL ; return it; } #include "template.h" diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 509811eb..7af54c58 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -234,7 +234,7 @@ STC_INLINE cstr_iter cstr_end(const cstr* self) { STC_INLINE void cstr_next(cstr_iter* it) { it->ref += it->u8.chr.size; it->u8.chr.size = utf8_chr_size(it->ref); - if (it->ref == it->u8._end) it->ref = NULL; + if (it->ref == it->u8.end) it->ref = NULL; } diff --git a/include/stc/csview.h b/include/stc/csview.h index c48c6ae6..5db23a01 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -81,7 +81,7 @@ STC_INLINE csview_iter csview_end(const csview* self) STC_INLINE void csview_next(csview_iter* it) { it->ref += it->u8.chr.size; it->u8.chr.size = utf8_chr_size(it->ref); - if (it->ref == it->u8._end) it->ref = NULL; + if (it->ref == it->u8.end) it->ref = NULL; } diff --git a/include/stc/cvec.h b/include/stc/cvec.h index a5e1fac6..86646026 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -106,7 +106,7 @@ _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], cons } STC_INLINE _cx_iter _cx_memb(_emplace_at)(_cx_self* self, _cx_iter it, _cx_raw raw) { - return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it._end), &raw, &raw + 1); + return _cx_memb(_emplace_range_p)(self, (it.ref ? it.ref : it.end), &raw, &raw + 1); } #endif // !_i_no_emplace @@ -171,7 +171,7 @@ _cx_memb(_insert_n)(_cx_self* self, const size_t idx, const _cx_value arr[], con } STC_INLINE _cx_iter _cx_memb(_insert_at)(_cx_self* self, _cx_iter it, i_key value) { - return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it._end), &value, &value + 1); + return _cx_memb(_insert_range_p)(self, (it.ref ? it.ref : it.end), &value, &value + 1); } STC_INLINE _cx_iter @@ -184,7 +184,7 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { } STC_INLINE _cx_iter _cx_memb(_erase_range)(_cx_self* self, _cx_iter i1, _cx_iter i2) { - return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2._end)); + return _cx_memb(_erase_range_p)(self, i1.ref, (i2.ref ? i2.ref : i2.end)); } STC_INLINE const _cx_value* @@ -206,10 +206,10 @@ STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) { return c_make(_cx_iter){NULL, self->data + cvec_rep_(self)->size}; } STC_INLINE void _cx_memb(_next)(_cx_iter* it) - { if (++it->ref == it->_end) it->ref = NULL; } + { if (++it->ref == it->end) it->ref = NULL; } STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) - { if ((it.ref += n) >= it._end) it.ref = NULL; return it; } + { if ((it.ref += n) >= it.end) it.ref = NULL; return it; } STC_INLINE size_t _cx_memb(_index)(const _cx_self* cx, _cx_iter it) { return it.ref - cx->data; } @@ -245,7 +245,7 @@ _cx_memb(_lower_bound)(const _cx_self* self, _cx_raw raw) { STC_INLINE void _cx_memb(_sort_range)(_cx_iter i1, _cx_iter i2, int(*cmp)(const _cx_value*, const _cx_value*)) { - qsort(i1.ref, (i2.ref ? i2.ref : i2._end) - i1.ref, sizeof(_cx_value), + qsort(i1.ref, (i2.ref ? i2.ref : i2.end) - i1.ref, sizeof(_cx_value), (int(*)(const void*, const void*)) cmp); } @@ -402,7 +402,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, #if !c_option(c_no_cmp) STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { - const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + const _cx_value* p2 = i2.ref ? i2.ref : i2.end; for (; i1.ref != p2; ++i1.ref) { const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) @@ -413,7 +413,7 @@ _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { STC_DEF _cx_iter _cx_memb(_binary_search_in)(_cx_iter i1, _cx_iter i2, const _cx_raw raw, _cx_iter* lower_bound) { - const _cx_value* p2 = i2.ref ? i2.ref : i2._end; + const _cx_value* p2 = i2.ref ? i2.ref : i2.end; _cx_iter mid = i1; while (i1.ref != p2) { mid.ref = i1.ref + (p2 - i1.ref)/2; @@ -424,7 +424,7 @@ _cx_memb(_binary_search_in)(_cx_iter i1, _cx_iter i2, const _cx_raw raw, _cx_ite else if (c < 0) p2 = mid.ref; else i1.ref = mid.ref + 1; } - *lower_bound = i1.ref == i2._end ? i2 : i1; + *lower_bound = i1.ref == i2.end ? i2 : i1; return i2; } diff --git a/include/stc/forward.h b/include/stc/forward.h index 9be399af..8a0278a5 100644 --- a/include/stc/forward.h +++ b/include/stc/forward.h @@ -57,7 +57,7 @@ typedef struct { const char* str; size_t size; } csview; typedef char csview_value; typedef union { const char *ref; - struct { csview chr; const char *_end; } u8; + struct { csview chr; const char *end; } u8; } csview_iter, cstr_iter; #define c_true(...) __VA_ARGS__ @@ -73,12 +73,12 @@ typedef union { #define _c_carr2_types(SELF, VAL) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct { SELF##_value **data; size_t xdim, ydim; } SELF #define _c_carr3_types(SELF, VAL) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct { SELF##_value ***data; size_t xdim, ydim, zdim; } SELF #define _c_cbox_types(SELF, VAL) \ @@ -89,7 +89,7 @@ typedef union { #define _c_cdeq_types(SELF, VAL) \ typedef VAL SELF##_value; \ - typedef struct {SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct {SELF##_value *ref, *end; } SELF##_iter; \ typedef struct {SELF##_value *_base, *data;} SELF #define _c_clist_types(SELF, VAL) \ @@ -120,7 +120,7 @@ typedef union { } SELF##_result; \ \ typedef struct { \ - SELF##_value *ref, *_end; \ + SELF##_value *ref, *end; \ uint8_t* _hx; \ } SELF##_iter; \ \ @@ -186,7 +186,7 @@ typedef union { #endif #define _c_cstack_types(SELF, VAL) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct SELF { \ SELF##_value* data; \ size_t size, capacity; \ @@ -194,7 +194,7 @@ typedef union { #define _c_cstack_fixed(SELF, VAL, CAP) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct SELF { \ SELF##_value data[CAP]; \ size_t size; \ @@ -209,7 +209,7 @@ typedef union { #define _c_cvec_types(SELF, VAL) \ typedef VAL SELF##_value; \ - typedef struct { SELF##_value *ref, *_end; } SELF##_iter; \ + typedef struct { SELF##_value *ref, *end; } SELF##_iter; \ typedef struct { SELF##_value *data; } SELF #endif // STC_FORWARD_H_INCLUDED -- cgit v1.2.3