From 57de677b5b00e0aa75772d6b5fe6347edbe03ffd Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sat, 16 Apr 2022 17:12:14 +0200 Subject: Added at_mut() to some containers. Added put_r() to cmap, csmap as alias for emplace_or_assign(). --- include/stc/cmap.h | 7 ++++++- include/stc/csmap.h | 6 ++++++ include/stc/cstack.h | 2 ++ include/stc/cstr.h | 2 +- include/stc/cvec.h | 13 ++++++++----- 5 files changed, 23 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/stc/cmap.h b/include/stc/cmap.h index af14cd1e..1a3e7944 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -110,10 +110,12 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } #ifndef _i_isset + STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); #if !defined _i_no_clone && !defined _i_no_emplace STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); + STC_INLINE _cx_result _cx_memb(_put_r)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) + { return _cx_memb(_emplace_or_assign)(self, rkey, rmapped); } #endif - STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); STC_INLINE _cx_result _cx_memb(_put)(_cx_self* self, i_key _key, i_val _mapped) @@ -125,6 +127,9 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey) assert(self->_hashx[b.idx]); return &self->table[b.idx].second; } + STC_INLINE _cx_mapped* + _cx_memb(_at_mut)(_cx_self* self, i_keyraw rkey) + { return (_cx_mapped*)_cx_memb(_at)(self, rkey); } #endif // !_i_isset #if !defined _i_no_clone diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 48dc053a..682f123b 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -158,6 +158,9 @@ _cx_memb(_value_drop)(_cx_value* val) { #ifndef _i_isset #if !defined _i_no_clone && !defined _i_no_emplace STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); + STC_INLINE _cx_result + _cx_memb(_put_r)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) + { return _cx_memb(_emplace_or_assign)(self, rkey, rmapped); } #endif STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped); @@ -168,6 +171,9 @@ _cx_memb(_value_drop)(_cx_value* val) { STC_INLINE const _cx_mapped* _cx_memb(_at)(const _cx_self* self, i_keyraw rkey) { _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; } + STC_INLINE _cx_mapped* + _cx_memb(_at_mut)(_cx_self* self, i_keyraw rkey) + { _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; } #endif // !_i_isset STC_INLINE _cx_iter diff --git a/include/stc/cstack.h b/include/stc/cstack.h index caa934df..b33319c5 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -98,6 +98,8 @@ STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < self->size); return self->data + idx; } +STC_INLINE _cx_value* _cx_memb(_at_mut)(_cx_self* self, size_t idx) + { assert(idx < self->size); return self->data + idx; } #if !defined _i_no_clone #if !defined _i_no_emplace diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 1e93a0ef..8347778c 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -185,7 +185,7 @@ cstr_reserve(cstr* self, const size_t cap) { cstr_priv* p = _cstr_p(self); const size_t oldcap = p->cap; if (cap > oldcap) { - p = (cstr_priv*) c_realloc((oldcap != 0) & (p != &_cstr_nullrep) ? p : NULL, _cstr_opt_mem(cap)); + p = (cstr_priv*) c_realloc(((oldcap != 0) & (p != &_cstr_nullrep)) ? p : NULL, _cstr_opt_mem(cap)); self->str = p->chr; if (oldcap == 0) self->str[p->size = 0] = '\0'; p->cap = _cstr_opt_cap(cap); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 6db8e3c7..52cac08a 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -134,11 +134,11 @@ STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_s STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; } STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + cvec_rep_(self)->size - 1; } +STC_INLINE void _cx_memb(_pop)(_cx_self* self) + { _cx_value* p = &self->data[--cvec_rep_(self)->size]; i_valdrop(p); } STC_INLINE _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value) { return _cx_memb(_push)(self, value); } -STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) - { _cx_value* p = &self->data[--cvec_rep_(self)->size]; i_valdrop(p); } -STC_INLINE void _cx_memb(_pop)(_cx_self* self) { _cx_memb(_pop_back)(self); } +STC_INLINE void _cx_memb(_pop_back)(_cx_self* self) { _cx_memb(_pop)(self); } STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self) { return c_make(_cx_iter){self->data}; } STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self) @@ -195,8 +195,11 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, const size_t idx) { - assert(idx < cvec_rep_(self)->size); - return self->data + idx; + assert(idx < cvec_rep_(self)->size); return self->data + idx; +} +STC_INLINE _cx_value* +_cx_memb(_at_mut)(_cx_self* self, const size_t idx) { + assert(idx < cvec_rep_(self)->size); return self->data + idx; } #if !c_option(c_no_cmp) -- cgit v1.2.3