diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/filter.h | 2 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 10 | ||||
| -rw-r--r-- | include/stc/cqueue.h | 32 | ||||
| -rw-r--r-- | include/stc/cstack.h | 7 | ||||
| -rw-r--r-- | include/stc/cvec.h | 3 |
5 files changed, 31 insertions, 23 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index db076ae4..fe733c64 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -106,7 +106,7 @@ int main() for (_i = it; it.ref; C##_next(&it)) \ if (pred) C##_value_drop(it.ref), ++_n; \ else *_i.ref = *it.ref, C##_next(&_i); \ - _cnt->_len -= _n; \ + C##_adjust_end_(_cnt, -_n); \ } while (0) // ------------------------ private ------------------------- diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 80dd1dbe..100a6b19 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -46,9 +46,8 @@ _cx_memb(_at_mut)(_cx_self* self, intptr_t idx) { return self->data + _cdeq_topos(self, idx); } STC_INLINE _cx_value* -_cx_memb(_push_back)(_cx_self* self, _cx_value val) { - return _cx_memb(_push)(self, val); -} +_cx_memb(_push_back)(_cx_self* self, _cx_value val) + { return _cx_memb(_push)(self, val); } STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { @@ -141,14 +140,13 @@ _cx_memb(_erase_n)(_cx_self* self, const intptr_t idx, const intptr_t n) { STC_DEF _cx_iter _cx_memb(_insert_uninit)(_cx_self* self, const intptr_t idx, const intptr_t n) { const intptr_t len = _cx_memb(_size)(self); - _cx_iter it = {._s=self}; + _cx_iter it = {.pos=_cdeq_topos(self, idx), ._s=self}; if (len + n > self->capmask) if (!_cx_memb(_reserve)(self, len + n)) return it; for (intptr_t j = len - 1, i = j + n; j >= idx; --j, --i) *_cx_memb(_at_mut)(self, i) = *_cx_memb(_at)(self, j); self->end = (self->end + n) & self->capmask; - it.pos = _cdeq_topos(self, idx); it.ref = self->data + it.pos; return it; } @@ -172,7 +170,7 @@ _cx_memb(_emplace_n)(_cx_self* self, const intptr_t idx, const _cx_raw* raw, con #if defined _i_has_eq || defined _i_has_cmp STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter i1, _cx_iter i2, _cx_raw raw) { - for (; i1.ref; _cx_memb(_next)(&i1)) { + for (; i1.pos != i2.pos; _cx_memb(_next)(&i1)) { const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) break; diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h index 09a747e5..d880d1fd 100644 --- a/include/stc/cqueue.h +++ b/include/stc/cqueue.h @@ -76,17 +76,14 @@ STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* pval) { return i_keyto(pval); } -STC_INLINE _cx_value* -_cx_memb(_front)(const _cx_self* self) - { return self->data + self->start; } +STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) + { return self->data + self->start; } -STC_INLINE _cx_value* -_cx_memb(_back)(const _cx_self* self) - { return self->data + ((self->end - 1) & self->capmask); } +STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) + { return self->data + ((self->end - 1) & self->capmask); } -STC_INLINE void -_cx_memb(_pop)(_cx_self* self) { // pop_front - c_ASSERT(!_cx_memb(_empty)(self)); +STC_INLINE void _cx_memb(_pop)(_cx_self* self) { // pop_front + assert(!_cx_memb(_empty)(self)); i_keydrop((self->data + self->start)); self->start = (self->start + 1) & self->capmask; } @@ -97,25 +94,28 @@ STC_INLINE void _cx_memb(_copy)(_cx_self* self, const _cx_self* other) { *self = _cx_memb(_clone)(*other); } -STC_INLINE _cx_iter -_cx_memb(_begin)(const _cx_self* self) { +STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { return c_LITERAL(_cx_iter){ _cx_memb(_empty)(self) ? NULL : self->data + self->start, self->start, self }; } -STC_INLINE _cx_iter -_cx_memb(_end)(const _cx_self* self) - { return c_LITERAL(_cx_iter){NULL, self->end, self}; } +STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) + { return c_LITERAL(_cx_iter){.pos=self->end, ._s=self}; } -STC_INLINE void -_cx_memb(_next)(_cx_iter* it) { +STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (it->pos != it->_s->capmask) { ++it->ref; ++it->pos; } else { it->ref -= it->pos; it->pos = 0; } if (it->pos == it->_s->end) it->ref = NULL; } +STC_INLINE intptr_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) + { return _cdeq_toidx(self, it.pos); } + +STC_INLINE void _cx_memb(_adjust_end_)(_cx_self* self, intptr_t n) + { self->end = (self->end + n) & self->capmask; } + /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 87ef9405..84bdb41b 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -80,6 +80,7 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self) { i_free(self->data); #endif } + STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* self) { return self->_len; } @@ -187,4 +188,10 @@ STC_INLINE void _cx_memb(_next)(_cx_iter* 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; } +STC_INLINE intptr_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) + { return (it.ref - self->data); } + +STC_INLINE void _cx_memb(_adjust_end_)(_cx_self* self, intptr_t n) + { self->_len += n; } + #include "priv/template2.h" diff --git a/include/stc/cvec.h b/include/stc/cvec.h index a7eb1a05..1a0fb118 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -207,6 +207,9 @@ STC_INLINE _cx_iter _cx_memb(_advance)(_cx_iter it, size_t n) STC_INLINE intptr_t _cx_memb(_index)(const _cx_self* self, _cx_iter it) { return (it.ref - self->data); } +STC_INLINE void _cx_memb(_adjust_end_)(_cx_self* self, intptr_t n) + { self->_len += n; } + #if !defined i_no_cmp || defined _i_has_eq STC_INLINE _cx_iter |
