diff options
| author | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
| commit | b677a0c3950b8294ba6458e682a885351273ac08 (patch) | |
| tree | f309f7f7571fb588f0f65254d17fa09d678a8e3c /include/stc/cpque.h | |
| parent | a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e (diff) | |
| download | STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.tar.gz STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.zip | |
Converted all containers but the maps and examples to signed sizes and indices.
Diffstat (limited to 'include/stc/cpque.h')
| -rw-r--r-- | include/stc/cpque.h | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 59419f16..21130864 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -41,19 +41,19 @@ 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, size_t idx); +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_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, size_t n) +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, size_t n) +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 size_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 *)c_realloc(self->data, cap*sizeof *d); return d ? (self->data = d, self->_cap = cap, true) : false; @@ -62,32 +62,32 @@ STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { 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 size_t 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 size_t size, i_key null) { +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) { - size_t i = self->_len; self->_len = 0; + 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); c_free(self->data); } -STC_INLINE size_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) { return !q->_len; } -STC_INLINE size_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) @@ -117,9 +117,9 @@ STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) #if defined(i_implement) STC_DEF void -_cx_memb(_sift_down_)(_cx_self* self, const size_t idx, const size_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 (size_t r = idx, c = idx*2; c <= n; c *= 2) { + for (intptr_t r = idx, c = idx*2; c <= n; c *= 2) { c += i_less_functor(self, (&arr[c]), (&arr[c + (c < n)])); if (!(i_less_functor(self, (&arr[r]), (&arr[c])))) return; t = arr[r], arr[r] = arr[c], arr[r = c] = t; @@ -128,8 +128,8 @@ _cx_memb(_sift_down_)(_cx_self* self, const size_t idx, const size_t n) { STC_DEF void _cx_memb(_make_heap)(_cx_self* self) { - size_t n = self->_len; - for (size_t k = n/2; k != 0; --k) + intptr_t n = self->_len; + for (intptr_t k = n/2; k != 0; --k) _cx_memb(_sift_down_)(self, k, n); } @@ -143,9 +143,9 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) { #endif STC_DEF void -_cx_memb(_erase_at)(_cx_self* self, const size_t idx) { +_cx_memb(_erase_at)(_cx_self* self, const intptr_t idx) { i_keydrop((self->data + idx)); - const size_t n = --self->_len; + const intptr_t n = --self->_len; self->data[idx] = self->data[n]; _cx_memb(_sift_down_)(self, idx + 1, n); } @@ -155,7 +155,7 @@ _cx_memb(_push)(_cx_self* self, _cx_value value) { if (self->_len == self->_cap) _cx_memb(_reserve)(self, self->_len*3/2 + 4); _cx_value *arr = self->data - 1; /* base 1 */ - size_t c = ++self->_len; + intptr_t c = ++self->_len; for (; c > 1 && (i_less_functor(self, (&arr[c/2]), (&value))); c /= 2) arr[c] = arr[c/2]; arr[c] = value; |
