diff options
| author | Tyge Løvset <[email protected]> | 2023-01-19 19:27:07 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-19 19:27:07 +0100 |
| commit | 5aa48d538569463ffeda976d21f79edc5f276be4 (patch) | |
| tree | 6bbd87bc9e5041b2c3b69e14ec175536b8418630 /include/stc/cstack.h | |
| parent | 0c4c4f8bba17562735b67b2923cd23c773aa53a7 (diff) | |
| download | STC-modified-5aa48d538569463ffeda976d21f79edc5f276be4.tar.gz STC-modified-5aa48d538569463ffeda976d21f79edc5f276be4.zip | |
Add a from_n() method to containers (and put_n() to maps), to support new initialization.
Diffstat (limited to 'include/stc/cstack.h')
| -rw-r--r-- | include/stc/cstack.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index f4a86156..c1332769 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -44,11 +44,11 @@ typedef i_keyraw _cx_raw; STC_INLINE _cx_self _cx_memb(_init)(void) { - _cx_self s; s._len = 0; + _cx_self cx; cx._len = 0; #ifndef i_capacity - s._cap = 0; s.data = NULL; + cx._cap = 0; cx.data = NULL; #endif - return s; + return cx; } #ifdef i_capacity @@ -106,8 +106,7 @@ STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return false; } -STC_INLINE _cx_value* -_cx_memb(_append_uninit)(_cx_self *self, size_t n) { +STC_INLINE _cx_value* _cx_memb(_append_uninit)(_cx_self *self, size_t n) { size_t len = self->_len; if (!_cx_memb(_reserve)(self, len + n)) return NULL; self->_len += n; @@ -137,6 +136,12 @@ STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) { STC_INLINE void _cx_memb(_pop)(_cx_self* self) { assert(!_cx_memb(_empty)(self)); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); } +STC_INLINE void _cx_memb(_put_n)(_cx_self* self, const _cx_raw* raw, size_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) + { _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, size_t idx) { assert(idx < self->_len); return self->data + idx; } STC_INLINE _cx_value* _cx_memb(_at_mut)(_cx_self* self, size_t idx) |
