summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-09 00:14:50 +0200
committerTyge Løvset <[email protected]>2022-04-09 00:14:50 +0200
commit1a4223837d4e34a085f00e323759ee5f9cd81bd3 (patch)
tree9be8cb543c9043fa885e511b86595c91ea1f4fc5 /include
parent03065ed6ef93f88003cd6754ca4d50ba20a76ebd (diff)
downloadSTC-modified-1a4223837d4e34a085f00e323759ee5f9cd81bd3.tar.gz
STC-modified-1a4223837d4e34a085f00e323759ee5f9cd81bd3.zip
Universally added a put() function to all containers.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cdeq.h2
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cmap.h11
-rw-r--r--include/stc/cpque.h3
-rw-r--r--include/stc/csmap.h10
-rw-r--r--include/stc/cstack.h6
-rw-r--r--include/stc/cvec.h4
7 files changed, 21 insertions, 17 deletions
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 93e181c4..e9df8898 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -88,6 +88,8 @@ STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) {c_swap(_cx_se
STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); }
STC_INLINE i_valraw _cx_memb(_value_toraw)(_cx_value* pval) { return i_valto(pval); }
+STC_INLINE _cx_value* _cx_memb(_put)(_cx_self* self, i_val value)
+ { return _cx_memb(_push_back)(self, value); }
STC_INLINE void _cx_memb(_pop_front)(_cx_self* self)
{ i_valdrop(self->data); ++self->data; --cdeq_rep_(self)->size; }
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 5591c93a..54eb6801 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -125,6 +125,8 @@ STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw
#endif
#endif
+STC_INLINE _cx_value* _cx_memb(_put)(_cx_self* self, i_val value)
+ { return _cx_memb(_push_back)(self, value); }
STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; }
STC_INLINE bool _cx_memb(_empty)(_cx_self cx) { return cx.last == NULL; }
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index a8e23da5..6fb3974d 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -117,11 +117,6 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey)
#endif
STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped);
- STC_INLINE _cx_result /* short-form, like operator[]: */
- _cx_memb(_put)(_cx_self* self, i_key key, i_val mapped) {
- return _cx_memb(_insert_or_assign)(self, key, mapped);
- }
-
STC_INLINE const _cx_mapped*
_cx_memb(_at)(const _cx_self* self, i_keyraw rkey) {
chash_bucket_t b = _cx_memb(_bucket_)(self, &rkey);
@@ -175,6 +170,12 @@ _cx_memb(_insert)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
return _res;
}
+STC_INLINE _cx_result
+_cx_memb(_put)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
+ return _i_SET_ONLY( _cx_memb(_insert)(self, _key) )
+ _i_MAP_ONLY( _cx_memb(_insert_or_assign)(self, _key, _mapped) );
+}
+
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
_cx_size idx;
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 3fa561ed..c30d1f8b 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -42,6 +42,9 @@ 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(_push)(_cx_self* self, _cx_value value);
+STC_INLINE void _cx_memb(_put)(_cx_self* self, _cx_value value)
+ { _cx_memb(_push)(self, value); }
+
STC_INLINE _cx_self _cx_memb(_init)(void)
{ return c_make(_cx_self){NULL}; }
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index ea9e1984..a040203b 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -163,15 +163,17 @@ _cx_memb(_value_drop)(_cx_value* val) {
#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)
- { return _cx_memb(_insert_or_assign)(self, key, mapped); }
-
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; }
#endif
+STC_INLINE _cx_result
+_cx_memb(_put)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
+ return _i_SET_ONLY( _cx_memb(_insert)(self, _key) )
+ _i_MAP_ONLY( _cx_memb(_insert_or_assign)(self, _key, _mapped) );
+}
+
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
_cx_iter it;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index bbf4613b..76103139 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -87,13 +87,11 @@ STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) {
_cx_value* vp = self->data + self->size++;
*vp = val; return vp;
}
-STC_INLINE _cx_value* _cx_memb(_push_back)(_cx_self* self, _cx_value val)
+STC_INLINE _cx_value* _cx_memb(_put)(_cx_self* self, _cx_value val)
{ return _cx_memb(_push)(self, val); }
STC_INLINE void _cx_memb(_pop)(_cx_self* self)
{ _cx_value* p = &self->data[--self->size]; i_valdrop(p); }
-STC_INLINE void _cx_memb(_pop_back)(_cx_self* self)
- { _cx_memb(_pop)(self); }
STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx)
{ assert(idx < self->size); return self->data + idx; }
@@ -102,8 +100,6 @@ STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t 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_valfrom(raw)); }
-STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, _cx_raw raw)
- { return _cx_memb(_push)(self, i_valfrom(raw)); }
#endif
STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) {
_cx_self out = {(_cx_value *) c_malloc(v.size*sizeof(_cx_value)), v.size, v.size};
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 1990b15d..34e830ba 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -109,8 +109,6 @@ STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* po
const _cx_raw* p1, const _cx_raw* p2);
STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
{ return _cx_memb(_push_back)(self, i_valfrom(raw)); }
-STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, i_valraw raw)
- { return _cx_memb(_push_back)(self, i_valfrom(raw)); }
STC_INLINE _cx_iter
_cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], const size_t n) {
return _cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + n);
@@ -134,7 +132,7 @@ 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 _cx_value* _cx_memb(_push)(_cx_self* self, i_val value)
+STC_INLINE _cx_value* _cx_memb(_put)(_cx_self* self, i_val value)
{ return _cx_memb(_push_back)(self, value); }
STC_INLINE void _cx_memb(_pop_back)(_cx_self* self)
{ _cx_value* p = &self->data[--cvec_rep_(self)->size]; i_valdrop(p); }