summaryrefslogtreecommitdiffhomepage
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
parent03065ed6ef93f88003cd6754ca4d50ba20a76ebd (diff)
downloadSTC-modified-1a4223837d4e34a085f00e323759ee5f9cd81bd3.tar.gz
STC-modified-1a4223837d4e34a085f00e323759ee5f9cd81bd3.zip
Universally added a put() function to all containers.
-rw-r--r--docs/clist_api.md1
-rw-r--r--docs/cpque_api.md1
-rw-r--r--docs/cqueue_api.md1
-rw-r--r--docs/cset_api.md17
-rw-r--r--docs/csmap_api.md2
-rw-r--r--docs/csset_api.md5
-rw-r--r--docs/cstack_api.md4
-rw-r--r--docs/cvec_api.md3
-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
15 files changed, 39 insertions, 33 deletions
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 8f907eca..bbb17796 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -55,6 +55,7 @@ void clist_X_emplace_front(clist_X* self, i_valraw raw);
void clist_X_pop_front(clist_X* self);
void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back().
+void clist_X_put(clist_X* self, i_val value); // alias for push_back().
void clist_X_emplace_back(clist_X* self, i_valraw raw);
clist_X_iter clist_X_insert(clist_X* self, clist_X_iter it, i_val value); // return iter to new elem
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 97ac70f5..055d2065 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -42,6 +42,7 @@ i_val* cpque_X_top(const cpque_X* self);
void cpque_X_make_heap(cpque_X* self); // heapify the vector.
void cpque_X_push(cpque_X* self, i_val value);
+void cpque_X_put(cpque_X* self, i_val value); // alias for push()
void cpque_X_emplace(cpque_X* self, i_valraw raw); // converts from raw
void cpque_X_pop(cpque_X* self);
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index 0ecae014..75105928 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -35,6 +35,7 @@ cqueue_X_value* cqueue_X_front(const cqueue_X* self);
cqueue_X_value* cqueue_X_back(const cqueue_X* self);
cqueue_X_value* cqueue_X_push(cqueue_X* self, i_val value);
+cqueue_X_value* cqueue_X_put(cqueue_X* self, i_val value); // alias for push()
cqueue_X_value* cqueue_X_emplace(cqueue_X* self, i_valraw raw);
void cqueue_X_pop(cqueue_X* self);
diff --git a/docs/cset_api.md b/docs/cset_api.md
index b5f8073b..56c2669c 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -29,27 +29,28 @@ cset_X cset_X_clone(cset_x set);
void cset_X_clear(cset_X* self);
void cset_X_copy(cset_X* self, cset_X other);
-void cset_X_max_load_factor(cset_X* self, float max_load); // default: 0.85
+void cset_X_max_load_factor(cset_X* self, float max_load); // default: 0.85
bool cset_X_reserve(cset_X* self, size_t size);
void cset_X_shrink_to_fit(cset_X* self);
void cset_X_swap(cset_X* a, cset_X* b);
-void cset_X_drop(cset_X* self); // destructor
+void cset_X_drop(cset_X* self); // destructor
-size_t cset_X_size(cset_X set); // num. of allocated buckets
-size_t cset_X_capacity(cset_X set); // buckets * max_load_factor
+size_t cset_X_size(cset_X set); // num. of allocated buckets
+size_t cset_X_capacity(cset_X set); // buckets * max_load_factor
bool cset_X_empty(cset_X set);
size_t cset_X_bucket_count(cset_X set);
bool cset_X_contains(const cset_X* self, i_keyraw rkey);
-const cset_X_value* cset_X_get(const cset_X* self, i_keyraw rkey); // return NULL if not found
-cset_X_value* cset_X_get_mut(cset_X* self, i_keyraw rkey); // mutable get
+const cset_X_value* cset_X_get(const cset_X* self, i_keyraw rkey); // return NULL if not found
+cset_X_value* cset_X_get_mut(cset_X* self, i_keyraw rkey); // mutable get
cset_X_iter cset_X_find(const cset_X* self, i_keyraw rkey);
cset_X_result cset_X_insert(cset_X* self, i_key key);
+cset_X_result cset_X_put(cset_X* self, i_key key); // alias for insert()
cset_X_result cset_X_emplace(cset_X* self, i_keyraw rkey);
-size_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1
-cset_X_iter cset_X_erase_at(cset_X* self, cset_X_iter it); // return iter after it
+size_t cset_X_erase(cset_X* self, i_keyraw rkey); // return 0 or 1
+cset_X_iter cset_X_erase_at(cset_X* self, cset_X_iter it); // return iter after it
void cset_X_erase_entry(cset_X* self, cset_X_value* entry);
cset_X_iter cset_X_begin(const cset_X* self);
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index 964046b1..e6f5515c 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -62,7 +62,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_put(csmap_X* self, i_key key, i_val mapped); // same as insert_or_assign()
+csmap_X_result csmap_X_put(csmap_X* self, i_key key, i_val mapped); // alias for insert_or_assign()
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/docs/csset_api.md b/docs/csset_api.md
index 5a33c70c..0329a9df 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -42,11 +42,12 @@ csset_X_value* csset_X_find_it(const csset_X* self, i_keyraw rkey, csset_X
csset_X_iter csset_X_lower_bound(const csset_X* self, i_keyraw rkey); // find closest entry >= rkey
csset_X_result csset_X_insert(csset_X* self, i_key key);
+csset_X_result csset_X_put(csset_X* self, i_key key); // alias for insert()
csset_X_result csset_X_emplace(csset_X* self, i_keyraw rkey);
size_t csset_X_erase(csset_X* self, i_keyraw rkey);
-csset_X_iter csset_X_erase_at(csset_X* self, csset_X_iter it); // return iter after it
-csset_X_iter csset_X_erase_range(csset_X* self, csset_X_iter it1, csset_X_iter it2); // return updated it2
+csset_X_iter csset_X_erase_at(csset_X* self, csset_X_iter it); // return iter after it
+csset_X_iter csset_X_erase_range(csset_X* self, csset_X_iter it1, csset_X_iter it2); // return updated it2
csset_X_iter csset_X_begin(const csset_X* self);
csset_X_iter csset_X_end(const csset_X* self);
diff --git a/docs/cstack_api.md b/docs/cstack_api.md
index 417e8d80..e6348489 100644
--- a/docs/cstack_api.md
+++ b/docs/cstack_api.md
@@ -41,12 +41,10 @@ i_val* cstack_X_top(const cstack_X* self);
const i_val* cstack_X_at(const cstack_X* self, size_t idx);
i_val* cstack_X_push(cstack_X* self, i_val value);
-i_val* cstack_X_push_back(cstack_X* self, i_val value); // same as push
+i_val* cstack_X_put(cstack_X* self, i_val value); // alias for push
i_val* cstack_X_emplace(cstack_X* self, i_valraw raw);
-i_val* cstack_X_emplace_back(cstack_X* self, i_valraw raw); // same as emplace
void cstack_X_pop(cstack_X* self);
-void cstack_X_pop_back(cstack_X* self); // same as pop
cstack_X_iter cstack_X_begin(const cstack_X* self);
cstack_X_iter cstack_X_end(const cstack_X* self);
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index c1d46f6d..a1ac6a4f 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -61,8 +61,7 @@ cvec_X_value* cvec_X_back(const cvec_X* self);
cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw);
cvec_X_value* cvec_X_push_back(cvec_X* self, i_val value);
void cvec_X_pop_back(cvec_X* self);
-cvec_X_value* cvec_X_emplace(cvec_X* self, i_valraw raw); // alias for emplace_back
-cvec_X_value* cvec_X_push(cvec_X* self, i_val value); // alias for push_back
+cvec_X_value* cvec_X_put(cvec_X* self, i_val value); // alias for push_back
void cvec_X_pop(cvec_X* self); // alias for pop_back
cvec_X_iter cvec_X_insert(cvec_X* self, size_t idx, i_val value); // move value
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); }