diff options
| author | Tyge Løvset <[email protected]> | 2022-04-15 23:30:24 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-15 23:30:24 +0200 |
| commit | 9723c34b18448cd28b10ac70d10f8bc156e6874f (patch) | |
| tree | abc4538d5e639ab65be921c3cc3dff4bf116bad1 | |
| parent | c75fd8e4e49a245b58678c5d92abfa0823ab3eed (diff) | |
| download | STC-modified-9723c34b18448cd28b10ac70d10f8bc156e6874f.tar.gz STC-modified-9723c34b18448cd28b10ac70d10f8bc156e6874f.zip | |
Internal.
| -rw-r--r-- | docs/cvec_api.md | 30 | ||||
| -rw-r--r-- | include/stc/cstack.h | 3 | ||||
| -rw-r--r-- | include/stc/cvec.h | 14 |
3 files changed, 24 insertions, 23 deletions
diff --git a/docs/cvec_api.md b/docs/cvec_api.md index e8669395..660f7a67 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -58,13 +58,13 @@ cvec_X_iter cvec_X_bsearch_in(cvec_X_iter i1, cvec_X_iter i2, i_valraw r cvec_X_value* cvec_X_front(const cvec_X* self); cvec_X_value* cvec_X_back(const cvec_X* self); -cvec_X_value* cvec_X_push_back(cvec_X* self, i_val value); -cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw); -cvec_X_value* cvec_X_push(cvec_X* self, i_val value); // alias for push_back -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); +cvec_X_value* cvec_X_emplace(cvec_X* self, i_valraw raw); +cvec_X_value* cvec_X_push_back(cvec_X* self, i_val value); // alias for push +cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw); // alias for emplace -void cvec_X_pop_back(cvec_X* self); -void cvec_X_pop(cvec_X* self); // alias for pop_back +void cvec_X_pop(cvec_X* self); +void cvec_X_pop_back(cvec_X* self); // alias for pop cvec_X_iter cvec_X_insert(cvec_X* self, size_t idx, i_val value); // move value cvec_X_iter cvec_X_insert_n(cvec_X* self, size_t idx, const i_val[] arr, size_t n); // move n values @@ -117,11 +117,11 @@ int main() c_auto (cvec_int, vec) { // Add two integers to vector - cvec_int_push_back(&vec, 25); - cvec_int_push_back(&vec, 13); + cvec_int_push(&vec, 25); + cvec_int_push(&vec, 13); // Append a set of numbers - c_apply(v, cvec_int_push_back(&vec, v), int, {7, 5, 16, 8}); + c_apply(v, cvec_int_push(&vec, v), int, {7, 5, 16, 8}); printf("initial:"); c_foreach (k, cvec_int, vec) { @@ -152,14 +152,14 @@ sorted: 5 7 8 13 16 25 int main() { cvec_str names = cvec_str_init(); - cvec_str_emplace_back(&names, "Mary"); - cvec_str_emplace_back(&names, "Joe"); + cvec_str_emplace(&names, "Mary"); + cvec_str_emplace(&names, "Joe"); cstr_assign(&names.data[1], "Jake"); // replace "Joe". cstr tmp = cstr_from_fmt("%d elements so far", cvec_str_size(names)); - // emplace_back() will not compile if adding a new cstr type. Use push_back(): - cvec_str_push_back(&names, tmp); // tmp is moved to names, do not drop() it. + // emplace() will not compile if adding a new cstr type. Use push_back(): + cvec_str_push(&names, tmp); // tmp is moved to names, do not drop() it. printf("%s\n", names.data[1].str); // Access the second element @@ -209,8 +209,8 @@ User User_clone(User user) { int main(void) { cvec_u vec = cvec_u_init(); - cvec_u_push_back(&vec, (User) {cstr_new("admin"), 0}); - cvec_u_push_back(&vec, (User) {cstr_new("joe"), 1}); + cvec_u_push(&vec, (User) {cstr_new("admin"), 0}); + cvec_u_push(&vec, (User) {cstr_new("joe"), 1}); cvec_u vec2 = cvec_u_clone(vec); c_foreach (i, cvec_u, vec2) diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 079d9bd0..caa934df 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -83,7 +83,8 @@ STC_INLINE _cx_value* _cx_memb(_top)(const _cx_self* self) { return &self->data[self->size - 1]; }
STC_INLINE _cx_value* _cx_memb(_push)(_cx_self* self, _cx_value val) {
- if (self->size == self->capacity) _cx_memb(_reserve)(self, self->size*3/2 + 4);
+ if (self->size == self->capacity)
+ _cx_memb(_reserve)(self, self->size*3/2 + 4);
_cx_value* vp = self->data + self->size++;
*vp = val; return vp;
}
diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 56b0742f..6db8e3c7 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -82,7 +82,7 @@ STC_API void _cx_memb(_drop)(_cx_self* self); STC_API void _cx_memb(_clear)(_cx_self* self);
STC_API bool _cx_memb(_reserve)(_cx_self* self, size_t cap);
STC_API bool _cx_memb(_resize)(_cx_self* self, size_t size, i_val null);
-STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value);
+STC_API _cx_value* _cx_memb(_push)(_cx_self* self, i_val value);
STC_API _cx_iter _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2);
STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos,
const _cx_value* p1, const _cx_value* p2);
@@ -107,10 +107,10 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { #if !defined _i_no_emplace
STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos,
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)); }
+ { return _cx_memb(_push)(self, i_valfrom(raw)); }
+STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw)
+ { return _cx_memb(_push)(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,8 +134,8 @@ 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)
- { return _cx_memb(_push_back)(self, value); }
+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); }
@@ -300,7 +300,7 @@ _cx_memb(_resize)(_cx_self* self, const size_t len, i_val null) { }
STC_DEF _cx_value*
-_cx_memb(_push_back)(_cx_self* self, i_val value) {
+_cx_memb(_push)(_cx_self* self, i_val value) {
struct cvec_rep *r = cvec_rep_(self);
if (r->size == r->cap) {
_cx_memb(_reserve)(self, (r->size*3 >> 1) + 4);
|
