diff options
| author | Tyge Løvset <[email protected]> | 2020-12-08 20:20:52 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-08 20:20:52 +0100 |
| commit | bfd7248535ee2bc6c067cb56894966968dc1ee82 (patch) | |
| tree | 2496237e6905492e1d36ea9d4bddc540675ddb02 | |
| parent | c9456324d1122d0c6135db8f2feda1913dd2cf69 (diff) | |
| download | STC-modified-bfd7248535ee2bc6c067cb56894966968dc1ee82.tar.gz STC-modified-bfd7248535ee2bc6c067cb56894966968dc1ee82.zip | |
Added clone() to stack, cpqueue and queue.
Renamed erase_at() to erase_n() in cvec and cstr to improve consistency.
| -rw-r--r-- | docs/cstr_api.md | 2 | ||||
| -rw-r--r-- | docs/cvec_api.md | 3 | ||||
| -rw-r--r-- | examples/demos.c | 6 | ||||
| -rw-r--r-- | stc/cpqueue.h | 2 | ||||
| -rw-r--r-- | stc/cqueue.h | 6 | ||||
| -rw-r--r-- | stc/cstack.h | 6 | ||||
| -rw-r--r-- | stc/cstr.h | 4 | ||||
| -rw-r--r-- | stc/cvec.h | 2 |
8 files changed, 18 insertions, 13 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index d3c86532..6624e779 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -68,7 +68,7 @@ These returns properties of a string. `5-6)` returns reference, ie. pointer to t 4) void cstr_pop_back(cstr_t* self); 5) void cstr_insert(cstr_t* self, size_t pos, const char* str); 6) void cstr_insert_n(cstr_t* self, size_t pos, const char* str, size_t n); - 7) void cstr_erase(cstr_t* self, size_t pos, size_t n); + 7) void cstr_erase_n(cstr_t* self, size_t pos, size_t n); 8) void cstr_replace(cstr_t* self, size_t pos, size_t len, const char* str); 9) void cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n); ``` diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 7004acec..d109b66e 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -87,10 +87,9 @@ cvec_X_iter_t cvec_X_insert_range_p(cvec_X* self, cvec_X_value_t* pos, const cvec_X_value_t* pfirst, const cvec_X_value_t* pfinish); cvec_X_iter_t cvec_X_erase(cvec_X* self, cvec_X_iter_t pos); -cvec_X_iter_t cvec_X_erase_at(cvec_X* self, size_t idx); +cvec_X_iter_t cvec_X_erase_n(cvec_X* self, size_t idx, size_t n); cvec_X_iter_t cvec_X_erase_range(cvec_X* self, cvec_X_iter_t first, cvec_X_iter_t finish); cvec_X_iter_t cvec_X_erase_range_p(cvec_X* self, cvec_X_value_t* pfirst, cvec_X_value_t* pfinish); -cvec_X_iter_t cvec_X_erase_range_i(cvec_X* self, size_t ifirst, size_t ifinish); cvec_X_iter_t cvec_X_find(const cvec_X* self, RawValue val); cvec_X_iter_t cvec_X_find_in_range(const cvec_X* self, diff --git a/examples/demos.c b/examples/demos.c index 0355d32f..f5df2c00 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -14,7 +14,7 @@ void stringdemo1() cstr_insert(&cs, 3, "-two");
printf("%s.\n", cs.str);
- cstr_erase_at(&cs, 7, 5); // -nine
+ cstr_erase_n(&cs, 7, 5); // -nine
printf("%s.\n", cs.str);
cstr_replace(&cs, cstr_find(cs, "seven"), 5, "four");
@@ -45,10 +45,10 @@ void vectordemo1() cvec_ix_push_back(&bignums, i * i);
printf("erase - %d: %zu\n", 3, bignums.data[3]);
- cvec_ix_erase_at(&bignums, 3, 1); // erase index 3
+ cvec_ix_erase_n(&bignums, 3, 1); // erase index 3
cvec_ix_pop_back(&bignums); // erase the last
- cvec_ix_erase_at(&bignums, 0, 1); // erase the first
+ cvec_ix_erase_n(&bignums, 0, 1); // erase the first
for (size_t i = 0; i < cvec_size(bignums); ++i) {
printf("%zu: %zu\n", i, bignums.data[i]);
diff --git a/stc/cpqueue.h b/stc/cpqueue.h index e753b5cd..f7f8150c 100644 --- a/stc/cpqueue.h +++ b/stc/cpqueue.h @@ -57,6 +57,8 @@ typedef ctype##_input_t cpqueue_##X##_input_t; \
STC_INLINE cpqueue_##X \
cpqueue_##X##_init(void) {return ctype##_init();} \
+ STC_INLINE cpqueue_##X \
+ cpqueue_##X##_clone(cpqueue_##X pq) {return ctype##_clone(pq);} \
STC_INLINE size_t \
cpqueue_##X##_size(cpqueue_##X pq) {return ctype##_size(pq);} \
STC_INLINE bool \
diff --git a/stc/cqueue.h b/stc/cqueue.h index e0a34636..7ad87c62 100644 --- a/stc/cqueue.h +++ b/stc/cqueue.h @@ -64,12 +64,14 @@ typedef ctype##_input_t cqueue_##X##_input_t; \
STC_INLINE cqueue_##X \
cqueue_##X##_init(void) {return ctype##_init();} \
+ STC_INLINE cqueue_##X \
+ cqueue_##X##_clone(cqueue_##X q) {return ctype##_clone(q);} \
STC_INLINE void \
cqueue_##X##_del(cqueue_##X* self) {ctype##_del(self);} \
STC_INLINE size_t \
- cqueue_##X##_size(cqueue_##X pq) {return ctype##_size(pq);} \
+ cqueue_##X##_size(cqueue_##X q) {return ctype##_size(q);} \
STC_INLINE bool \
- cqueue_##X##_empty(cqueue_##X pq) {return ctype##_empty(pq);} \
+ cqueue_##X##_empty(cqueue_##X q) {return ctype##_empty(q);} \
STC_INLINE cqueue_##X##_value_t* \
cqueue_##X##_front(cqueue_##X* self) {return ctype##_front(self);} \
STC_INLINE cqueue_##X##_value_t* \
diff --git a/stc/cstack.h b/stc/cstack.h index 170e6f45..45abd596 100644 --- a/stc/cstack.h +++ b/stc/cstack.h @@ -53,12 +53,14 @@ typedef ctype##_input_t cstack_##X##_input_t; \
STC_INLINE cstack_##X \
cstack_##X##_init(void) {return ctype##_init();} \
+ STC_INLINE cstack_##X \
+ cstack_##X##_clone(cstack_##X st) {return ctype##_clone(st);} \
STC_INLINE void \
cstack_##X##_del(cstack_##X* self) {ctype##_del(self);} \
STC_INLINE size_t \
- cstack_##X##_size(cstack_##X pq) {return ctype##_size(pq);} \
+ cstack_##X##_size(cstack_##X st) {return ctype##_size(st);} \
STC_INLINE bool \
- cstack_##X##_empty(cstack_##X pq) {return ctype##_empty(pq);} \
+ cstack_##X##_empty(cstack_##X st) {return ctype##_empty(st);} \
STC_INLINE cstack_##X##_value_t* \
cstack_##X##_top(cstack_##X* self) {return ctype##_back(self);} \
STC_INLINE void \
@@ -56,7 +56,7 @@ cstr_append_n(cstr_t* self, const char* str, size_t len); STC_API void
cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n);
STC_API void
-cstr_erase_at(cstr_t* self, size_t pos, size_t n);
+cstr_erase_n(cstr_t* self, size_t pos, size_t n);
STC_API bool
cstr_getdelim(cstr_t *self, int delim, FILE *stream);
STC_API size_t
@@ -370,7 +370,7 @@ cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n) }
STC_DEF void
-cstr_erase_at(cstr_t* self, size_t pos, size_t n) {
+cstr_erase_n(cstr_t* self, size_t pos, size_t n) {
size_t len = cstr_size(*self);
if (len) {
memmove(&self->str[pos], &self->str[pos + n], len - (pos + n));
@@ -139,7 +139,7 @@ return cvec_##X##_erase_range_p(self, pos.val, pos.val + 1); \
} \
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_erase_at(cvec_##X* self, size_t idx, size_t n) { \
+ cvec_##X##_erase_n(cvec_##X* self, size_t idx, size_t n) { \
return cvec_##X##_erase_range_p(self, self->data + idx, self->data + idx + n); \
} \
\
|
