diff options
| author | Tyge Lovset <[email protected]> | 2022-08-15 08:17:01 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-08-15 08:17:01 +0200 |
| commit | 2cfad29db0fda313873f2b4a809ff60aca897785 (patch) | |
| tree | 2af00342f8fde6f71876937fabd6852be69b5890 /include/stc/cvec.h | |
| parent | dd6e6a60b8d1af9127f2694efc314e810b71c9b1 (diff) | |
| download | STC-modified-2cfad29db0fda313873f2b4a809ff60aca897785.tar.gz STC-modified-2cfad29db0fda313873f2b4a809ff60aca897785.zip | |
Improved docs/ex. Fix range bug when container is empty cvec/cdeq.
Diffstat (limited to 'include/stc/cvec.h')
| -rw-r--r-- | include/stc/cvec.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/include/stc/cvec.h b/include/stc/cvec.h index c734abb6..170bf741 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -66,6 +66,7 @@ int main() { struct cvec_rep { size_t size, cap; unsigned data[1]; }; #define cvec_rep_(self) c_unchecked_container_of((self)->data, struct cvec_rep, data) +#define it2_ref_(it1, it2) (it1.ref && !it2.ref ? it2.end : it2.ref) #endif // CVEC_H_INCLUDED #ifndef _i_prefix @@ -181,7 +182,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, it2_ref_(i1, i2)); } STC_INLINE const _cx_value* @@ -242,7 +243,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, it2_ref_(i1, i2) - i1.ref, sizeof(_cx_value), (int(*)(const void*, const void*)) cmp); } @@ -404,7 +405,7 @@ _cx_memb(_emplace_range)(_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 = it2_ref_(i1, i2); for (; i1.ref != p2; ++i1.ref) { const _cx_raw r = i_keyto(i1.ref); if (i_eq((&raw), (&r))) @@ -416,7 +417,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 = it2_ref_(i1, i2); _cx_iter mid = i1; while (i1.ref != p2) { mid.ref = i1.ref + (p2 - i1.ref)/2; |
