summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-04-22 12:44:57 +0200
committerTyge Løvset <[email protected]>2022-04-22 12:44:57 +0200
commitdd5551dec268da39ad1c5c66de014e4621d24748 (patch)
tree104de218168bddaee937e92c919e0459d35209fc
parent8f57f3d331de4cb4aa7d06862c2de3424eb1ba5b (diff)
downloadSTC-modified-dd5551dec268da39ad1c5c66de014e4621d24748.tar.gz
STC-modified-dd5551dec268da39ad1c5c66de014e4621d24748.zip
Changed API for c*map_X_push() to take a entry pair (c*map_X_value) argument instead of key + val.
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/csmap_api.md2
-rw-r--r--include/stc/cmap.h6
-rw-r--r--include/stc/csmap.h13
4 files changed, 14 insertions, 9 deletions
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 645b0bd0..03ee11a9 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -67,7 +67,7 @@ cmap_X_iter cmap_X_find(const cmap_X* self, i_keyraw rkey);
cmap_X_result cmap_X_insert(cmap_X* self, i_key key, i_val mapped); // no change if key in map
cmap_X_result cmap_X_insert_or_assign(cmap_X* self, i_key key, i_val mapped); // always update mapped
-cmap_X_result cmap_X_push(cmap_X* self, i_key key, i_val mapped); // alias for insert
+cmap_X_result cmap_X_push(cmap_X* self, cmap_X_value entry); // similar to insert
cmap_X_result cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map
cmap_X_result cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index e73e6562..ab9eb2ee 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -63,7 +63,7 @@ csmap_X_value* csmap_X_back(const csmap_X* self);
csmap_X_result csmap_X_insert(csmap_X* self, i_key key, i_val mapped); // no change if key in map
csmap_X_result csmap_X_insert_or_assign(csmap_X* self, i_key key, i_val mapped); // always update mapped
-csmap_X_result csmap_X_push(csmap_X* self, i_key key, i_val mapped); // alias for insert()
+csmap_X_result csmap_X_push(csmap_X* self, csmap_X_value entry); // similar to insert()
csmap_X_result csmap_X_emplace(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map
csmap_X_result csmap_X_emplace_or_assign(csmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 16041094..6cde2532 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -178,8 +178,10 @@ _cx_memb(_insert)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
}
STC_INLINE _cx_result
-_cx_memb(_push)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
- return _cx_memb(_insert)(self, _key _i_MAP_ONLY(, _mapped));
+_cx_memb(_push)(_cx_self* self, _cx_value _val) {
+ _cx_result _res = _cx_memb(_insert_entry_)(self, i_keyto(_i_keyref(&_val)));
+ if (_res.inserted) *_res.ref = _val; else _cx_memb(_value_drop)(&_val);
+ return _res;
}
STC_INLINE _cx_iter
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 700aa4c2..25f66d79 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -104,6 +104,7 @@ STC_API _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_
#endif // !_i_no_clone
STC_API _cx_self _cx_memb(_init)(void);
STC_API _cx_result _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped));
+STC_API _cx_result _cx_memb(_push)(_cx_self* self, _cx_value _val);
STC_API void _cx_memb(_drop)(_cx_self* self);
STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t cap);
STC_API _cx_value* _cx_memb(_find_it)(const _cx_self* self, i_keyraw rkey, _cx_iter* out);
@@ -170,11 +171,6 @@ _cx_memb(_value_drop)(_cx_value* val) {
{ _cx_iter it; return &_cx_memb(_find_it)(self, rkey, &it)->second; }
#endif // !_i_isset
-STC_INLINE _cx_result
-_cx_memb(_push)(_cx_self* self, i_key _key _i_MAP_ONLY(, i_val _mapped)) {
- return _cx_memb(_insert)(self, _key _i_MAP_ONLY(, _mapped));
-}
-
STC_INLINE _cx_iter
_cx_memb(_find)(const _cx_self* self, i_keyraw rkey) {
_cx_iter it;
@@ -273,6 +269,13 @@ _cx_memb(_insert)(_cx_self* self, i_key key _i_MAP_ONLY(, i_val mapped)) {
return res;
}
+STC_DEF _cx_result
+_cx_memb(_push)(_cx_self* self, _cx_value _val) {
+ _cx_result _res = _cx_memb(_insert_entry_)(self, i_keyto(_i_keyref(&_val)));
+ if (_res.inserted) *_res.ref = _val; else _cx_memb(_value_drop)(&_val);
+ return _res;
+}
+
#ifndef _i_isset
STC_DEF _cx_result
_cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped) {