diff options
| author | _Tradam <[email protected]> | 2023-09-08 01:29:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 01:29:47 +0000 |
| commit | 3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch) | |
| tree | afbe4b540967223911f7c5de36559b82154f02f3 /include/stc/cpque.h | |
| parent | 0841165881871ee01b782129be681209aeed2423 (diff) | |
| parent | 1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff) | |
| download | STC-modified-3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd.tar.gz STC-modified-3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd.zip | |
Diffstat (limited to 'include/stc/cpque.h')
| -rw-r--r-- | include/stc/cpque.h | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index b95b5020..520514ef 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -20,101 +20,100 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "ccommon.h" +#include "priv/linkage.h" #ifndef CPQUE_H_INCLUDED +#include "ccommon.h" #include <stdlib.h> #include "forward.h" #endif -#ifndef _i_prefix #define _i_prefix cpque_ -#endif - +#define _i_ispque #include "priv/template.h" #ifndef i_is_forward - _cx_deftypes(_c_cpque_types, _cx_self, i_key); + _cx_DEFTYPES(_c_cpque_types, _cx_Self, i_key); #endif typedef i_keyraw _cx_raw; -STC_API void _cx_memb(_make_heap)(_cx_self* self); -STC_API void _cx_memb(_erase_at)(_cx_self* self, intptr_t idx); -STC_API void _cx_memb(_push)(_cx_self* self, _cx_value value); +STC_API void _cx_MEMB(_make_heap)(_cx_Self* self); +STC_API void _cx_MEMB(_erase_at)(_cx_Self* self, intptr_t idx); +STC_API _cx_value* _cx_MEMB(_push)(_cx_Self* self, _cx_value value); -STC_INLINE _cx_self _cx_memb(_init)(void) - { return c_LITERAL(_cx_self){NULL}; } +STC_INLINE _cx_Self _cx_MEMB(_init)(void) + { return c_LITERAL(_cx_Self){NULL}; } -STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, intptr_t n) - { while (n--) _cx_memb(_push)(self, i_keyfrom(*raw++)); } +STC_INLINE void _cx_MEMB(_put_n)(_cx_Self* self, const _cx_raw* raw, intptr_t n) + { while (n--) _cx_MEMB(_push)(self, i_keyfrom(*raw++)); } -STC_INLINE _cx_self _cx_memb(_from_n)(const _cx_raw* raw, intptr_t n) - { _cx_self cx = {0}; _cx_memb(_put_n)(&cx, raw, n); return cx; } +STC_INLINE _cx_Self _cx_MEMB(_from_n)(const _cx_raw* raw, intptr_t n) + { _cx_Self cx = {0}; _cx_MEMB(_put_n)(&cx, raw, n); return cx; } -STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const intptr_t cap) { +STC_INLINE bool _cx_MEMB(_reserve)(_cx_Self* self, const intptr_t cap) { if (cap != self->_len && cap <= self->_cap) return true; _cx_value *d = (_cx_value *)i_realloc(self->data, cap*c_sizeof *d); return d ? (self->data = d, self->_cap = cap, true) : false; } -STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self) - { _cx_memb(_reserve)(self, self->_len); } +STC_INLINE void _cx_MEMB(_shrink_to_fit)(_cx_Self* self) + { _cx_MEMB(_reserve)(self, self->_len); } -STC_INLINE _cx_self _cx_memb(_with_capacity)(const intptr_t cap) { - _cx_self out = {NULL}; _cx_memb(_reserve)(&out, cap); +STC_INLINE _cx_Self _cx_MEMB(_with_capacity)(const intptr_t cap) { + _cx_Self out = {NULL}; _cx_MEMB(_reserve)(&out, cap); return out; } -STC_INLINE _cx_self _cx_memb(_with_size)(const intptr_t size, i_key null) { - _cx_self out = {NULL}; _cx_memb(_reserve)(&out, size); +STC_INLINE _cx_Self _cx_MEMB(_with_size)(const intptr_t size, i_key null) { + _cx_Self out = {NULL}; _cx_MEMB(_reserve)(&out, size); while (out._len < size) out.data[out._len++] = null; return out; } -STC_INLINE void _cx_memb(_clear)(_cx_self* self) { +STC_INLINE void _cx_MEMB(_clear)(_cx_Self* self) { intptr_t i = self->_len; self->_len = 0; while (i--) { i_keydrop((self->data + i)); } } -STC_INLINE void _cx_memb(_drop)(_cx_self* self) - { _cx_memb(_clear)(self); i_free(self->data); } +STC_INLINE void _cx_MEMB(_drop)(_cx_Self* self) + { _cx_MEMB(_clear)(self); i_free(self->data); } -STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* q) +STC_INLINE intptr_t _cx_MEMB(_size)(const _cx_Self* q) { return q->_len; } -STC_INLINE bool _cx_memb(_empty)(const _cx_self* q) +STC_INLINE bool _cx_MEMB(_empty)(const _cx_Self* q) { return !q->_len; } -STC_INLINE intptr_t _cx_memb(_capacity)(const _cx_self* q) +STC_INLINE intptr_t _cx_MEMB(_capacity)(const _cx_Self* q) { return q->_cap; } -STC_INLINE const _cx_value* _cx_memb(_top)(const _cx_self* self) +STC_INLINE const _cx_value* _cx_MEMB(_top)(const _cx_Self* self) { return &self->data[0]; } -STC_INLINE void _cx_memb(_pop)(_cx_self* self) - { assert(!_cx_memb(_empty)(self)); _cx_memb(_erase_at)(self, 0); } +STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self) + { c_assert(!_cx_MEMB(_empty)(self)); _cx_MEMB(_erase_at)(self, 0); } #if !defined i_no_clone -STC_API _cx_self _cx_memb(_clone)(_cx_self q); +STC_API _cx_Self _cx_MEMB(_clone)(_cx_Self q); -STC_INLINE void _cx_memb(_copy)(_cx_self *self, const _cx_self* other) { +STC_INLINE void _cx_MEMB(_copy)(_cx_Self *self, const _cx_Self* other) { if (self->data == other->data) return; - _cx_memb(_drop)(self); - *self = _cx_memb(_clone)(*other); + _cx_MEMB(_drop)(self); + *self = _cx_MEMB(_clone)(*other); } -STC_INLINE i_key _cx_memb(_value_clone)(_cx_value val) +STC_INLINE i_key _cx_MEMB(_value_clone)(_cx_value val) { return i_keyclone(val); } #endif // !i_no_clone #if !defined i_no_emplace -STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) - { _cx_memb(_push)(self, i_keyfrom(raw)); } +STC_INLINE void _cx_MEMB(_emplace)(_cx_Self* self, _cx_raw raw) + { _cx_MEMB(_push)(self, i_keyfrom(raw)); } #endif // !i_no_emplace /* -------------------------- IMPLEMENTATION ------------------------- */ -#if defined(i_implement) +#if defined(i_implement) || defined(i_static) STC_DEF void -_cx_memb(_sift_down_)(_cx_self* self, const intptr_t idx, const intptr_t n) { +_cx_MEMB(_sift_down_)(_cx_Self* self, const intptr_t idx, const intptr_t n) { _cx_value t, *arr = self->data - 1; for (intptr_t r = idx, c = idx*2; c <= n; c *= 2) { c += i_less((&arr[c]), (&arr[c + (c < n)])); @@ -124,15 +123,15 @@ _cx_memb(_sift_down_)(_cx_self* self, const intptr_t idx, const intptr_t n) { } STC_DEF void -_cx_memb(_make_heap)(_cx_self* self) { +_cx_MEMB(_make_heap)(_cx_Self* self) { intptr_t n = self->_len; for (intptr_t k = n/2; k != 0; --k) - _cx_memb(_sift_down_)(self, k, n); + _cx_MEMB(_sift_down_)(self, k, n); } #if !defined i_no_clone -STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) { - _cx_self out = _cx_memb(_with_capacity)(q._len); +STC_DEF _cx_Self _cx_MEMB(_clone)(_cx_Self q) { + _cx_Self out = _cx_MEMB(_with_capacity)(q._len); for (; out._len < out._cap; ++q.data) out.data[out._len++] = i_keyclone((*q.data)); return out; @@ -140,24 +139,26 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) { #endif STC_DEF void -_cx_memb(_erase_at)(_cx_self* self, const intptr_t idx) { +_cx_MEMB(_erase_at)(_cx_Self* self, const intptr_t idx) { i_keydrop((self->data + idx)); const intptr_t n = --self->_len; self->data[idx] = self->data[n]; - _cx_memb(_sift_down_)(self, idx + 1, n); + _cx_MEMB(_sift_down_)(self, idx + 1, n); } -STC_DEF void -_cx_memb(_push)(_cx_self* self, _cx_value value) { +STC_DEF _cx_value* +_cx_MEMB(_push)(_cx_Self* self, _cx_value value) { if (self->_len == self->_cap) - _cx_memb(_reserve)(self, self->_len*3/2 + 4); + _cx_MEMB(_reserve)(self, self->_len*3/2 + 4); _cx_value *arr = self->data - 1; /* base 1 */ intptr_t c = ++self->_len; for (; c > 1 && (i_less((&arr[c/2]), (&value))); c /= 2) arr[c] = arr[c/2]; arr[c] = value; + return arr + c; } #endif #define CPQUE_H_INCLUDED #include "priv/template2.h" +#undef _i_ispque
\ No newline at end of file |
