diff options
| author | Tyge Løvset <[email protected]> | 2023-06-20 15:28:02 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-06-20 15:28:02 +0200 |
| commit | de4f8fa86f141dfeab15f5576029910474f56fa1 (patch) | |
| tree | 930f8ecb0a2765d4834aa34f6ac538096454816c /include/stc/cstack.h | |
| parent | b617eded8cee98dd3ff9ac896328b172d37fcf91 (diff) | |
| download | STC-modified-de4f8fa86f141dfeab15f5576029910474f56fa1.tar.gz STC-modified-de4f8fa86f141dfeab15f5576029910474f56fa1.zip | |
Internal only:
Renamed _cx_memb() macro to _cx_MEMB()
Renamed _cx_self macro to _cx_Self
Diffstat (limited to 'include/stc/cstack.h')
| -rw-r--r-- | include/stc/cstack.h | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 5f0ffe2b..24ec2d5f 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -35,64 +35,64 @@ #ifndef i_is_forward #ifdef i_capacity #define i_no_clone - _cx_deftypes(_c_cstack_fixed, _cx_self, i_key, i_capacity); + _cx_DEFTYPES(_c_cstack_fixed, _cx_Self, i_key, i_capacity); #else - _cx_deftypes(_c_cstack_types, _cx_self, i_key); + _cx_DEFTYPES(_c_cstack_types, _cx_Self, i_key); #endif #endif typedef i_keyraw _cx_raw; #ifdef i_capacity -STC_INLINE void _cx_memb(_init)(_cx_self* self) +STC_INLINE void _cx_MEMB(_init)(_cx_Self* self) { self->_len = 0; } #else -STC_INLINE _cx_self _cx_memb(_init)(void) { - _cx_self out = {0}; +STC_INLINE _cx_Self _cx_MEMB(_init)(void) { + _cx_Self out = {0}; return out; } -STC_INLINE _cx_self _cx_memb(_with_capacity)(intptr_t cap) { - _cx_self out = {(_cx_value *) i_malloc(cap*c_sizeof(i_key)), 0, cap}; +STC_INLINE _cx_Self _cx_MEMB(_with_capacity)(intptr_t cap) { + _cx_Self out = {(_cx_value *) i_malloc(cap*c_sizeof(i_key)), 0, cap}; return out; } -STC_INLINE _cx_self _cx_memb(_with_size)(intptr_t size, i_key null) { - _cx_self out = {(_cx_value *) i_malloc(size*c_sizeof null), size, size}; +STC_INLINE _cx_Self _cx_MEMB(_with_size)(intptr_t size, i_key null) { + _cx_Self out = {(_cx_value *) i_malloc(size*c_sizeof null), size, size}; while (size) out.data[--size] = null; return out; } #endif // i_capacity -STC_INLINE void _cx_memb(_clear)(_cx_self* self) { +STC_INLINE void _cx_MEMB(_clear)(_cx_Self* self) { _cx_value *p = self->data + self->_len; while (p-- != self->data) { i_keydrop(p); } self->_len = 0; } -STC_INLINE void _cx_memb(_drop)(_cx_self* self) { - _cx_memb(_clear)(self); +STC_INLINE void _cx_MEMB(_drop)(_cx_Self* self) { + _cx_MEMB(_clear)(self); #ifndef i_capacity i_free(self->data); #endif } -STC_INLINE intptr_t _cx_memb(_size)(const _cx_self* self) +STC_INLINE intptr_t _cx_MEMB(_size)(const _cx_Self* self) { return self->_len; } -STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) +STC_INLINE bool _cx_MEMB(_empty)(const _cx_Self* self) { return !self->_len; } -STC_INLINE intptr_t _cx_memb(_capacity)(const _cx_self* self) { +STC_INLINE intptr_t _cx_MEMB(_capacity)(const _cx_Self* self) { #ifndef i_capacity return self->_cap; #else return i_capacity; #endif } -STC_INLINE void _cx_memb(_value_drop)(_cx_value* val) +STC_INLINE void _cx_MEMB(_value_drop)(_cx_value* val) { i_keydrop(val); } -STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, intptr_t n) { +STC_INLINE bool _cx_MEMB(_reserve)(_cx_Self* self, intptr_t n) { if (n < self->_len) return true; #ifndef i_capacity _cx_value *t = (_cx_value *)i_realloc(self->data, n*c_sizeof *t); @@ -101,100 +101,100 @@ STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, intptr_t n) { return false; } -STC_INLINE _cx_value* _cx_memb(_append_uninit)(_cx_self *self, intptr_t n) { +STC_INLINE _cx_value* _cx_MEMB(_append_uninit)(_cx_Self *self, intptr_t n) { intptr_t len = self->_len; - if (!_cx_memb(_reserve)(self, len + n)) return NULL; + if (!_cx_MEMB(_reserve)(self, len + n)) return NULL; self->_len += n; return self->data + len; } -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 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[self->_len - 1]; } -STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) +STC_INLINE _cx_value* _cx_MEMB(_back)(const _cx_Self* self) { return (_cx_value*) &self->data[self->_len - 1]; } -STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) +STC_INLINE _cx_value* _cx_MEMB(_front)(const _cx_Self* self) { return (_cx_value*) &self->data[0]; } -STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) { - if (self->_len == _cx_memb(_capacity)(self)) - if (!_cx_memb(_reserve)(self, self->_len*3/2 + 4)) +STC_INLINE _cx_value* _cx_MEMB(_push)(_cx_Self* self, _cx_value val) { + if (self->_len == _cx_MEMB(_capacity)(self)) + if (!_cx_MEMB(_reserve)(self, self->_len*3/2 + 4)) return NULL; _cx_value* vp = self->data + self->_len++; *vp = val; return vp; } -STC_INLINE void _cx_memb(_pop)(_cx_self* self) +STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self) { assert(self->_len); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); } -STC_INLINE _cx_value _cx_memb(_pull)(_cx_self* self) +STC_INLINE _cx_value _cx_MEMB(_pull)(_cx_Self* self) { assert(self->_len); return self->data[--self->_len]; } -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 const _cx_value* _cx_memb(_at)(const _cx_self* self, intptr_t idx) +STC_INLINE const _cx_value* _cx_MEMB(_at)(const _cx_Self* self, intptr_t idx) { assert(idx < self->_len); return self->data + idx; } -STC_INLINE _cx_value* _cx_memb(_at_mut)(_cx_self* self, intptr_t idx) +STC_INLINE _cx_value* _cx_MEMB(_at_mut)(_cx_Self* self, intptr_t idx) { assert(idx < self->_len); return self->data + idx; } #if !defined i_no_emplace -STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) - { return _cx_memb(_push)(self, i_keyfrom(raw)); } +STC_INLINE _cx_value* _cx_MEMB(_emplace)(_cx_Self* self, _cx_raw raw) + { return _cx_MEMB(_push)(self, i_keyfrom(raw)); } #endif // !i_no_emplace #if !defined i_no_clone -STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { - _cx_self out = {(_cx_value *)i_malloc(v._len*c_sizeof(_cx_value)), v._len, v._len}; +STC_INLINE _cx_Self _cx_MEMB(_clone)(_cx_Self v) { + _cx_Self out = {(_cx_value *)i_malloc(v._len*c_sizeof(_cx_value)), v._len, v._len}; if (!out.data) out._cap = 0; else for (intptr_t i = 0; i < v._len; ++v.data) out.data[i++] = i_keyclone((*v.data)); return out; } -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); } -STC_INLINE i_keyraw _cx_memb(_value_toraw)(const _cx_value* val) +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) { +STC_INLINE _cx_iter _cx_MEMB(_begin)(const _cx_Self* self) { return c_LITERAL(_cx_iter){self->_len ? (_cx_value*)self->data : NULL, (_cx_value*)self->data + self->_len}; } -STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) +STC_INLINE _cx_iter _cx_MEMB(_end)(const _cx_Self* self) { return c_LITERAL(_cx_iter){NULL, (_cx_value*)self->data + self->_len}; } -STC_INLINE void _cx_memb(_next)(_cx_iter* it) +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) +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) +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) +STC_INLINE void _cx_MEMB(_adjust_end_)(_cx_Self* self, intptr_t n) { self->_len += n; } #if defined _i_has_eq || defined _i_has_cmp STC_INLINE bool -_cx_memb(_eq)(const _cx_self* self, const _cx_self* other) { +_cx_MEMB(_eq)(const _cx_Self* self, const _cx_Self* other) { if (self->_len != other->_len) return false; for (intptr_t i = 0; i < self->_len; ++i) { const _cx_raw _rx = i_keyto(self->data+i), _ry = i_keyto(other->data+i); |
