diff options
| author | Tyge Løvset <[email protected]> | 2020-09-11 10:10:53 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-11 10:10:53 +0200 |
| commit | a14f2621baf668aaa9952e46ad69849f12594add (patch) | |
| tree | de5eeec3cfd304f5c0a583331aa821a51f3dc96c | |
| parent | 8dd8368bca262dbab39741fbbb61c16478772e4e (diff) | |
| download | STC-modified-a14f2621baf668aaa9952e46ad69849f12594add.tar.gz STC-modified-a14f2621baf668aaa9952e46ad69849f12594add.zip | |
Some renaming of functions, API changes in list and vec.
| -rw-r--r-- | examples/phonebook.c | 4 | ||||
| -rw-r--r-- | stc/cdefs.h | 12 | ||||
| -rw-r--r-- | stc/clist.h | 11 | ||||
| -rw-r--r-- | stc/cmap.h | 7 | ||||
| -rw-r--r-- | stc/cvec.h | 12 |
5 files changed, 24 insertions, 22 deletions
diff --git a/examples/phonebook.c b/examples/phonebook.c index 50a16467..74105f25 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -47,8 +47,8 @@ int main(int argc, char **argv) printf("Phone book:\n");
print_phone_book(phone_book);
- cmap_try_emplace(str, &phone_book, "Zak Byers", cstr_make("(551) 396-1880"));
- cmap_try_emplace(str, &phone_book, "Zak Byers", cstr_make("(551) 396-1990"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_make("(551) 396-1880"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_make("(551) 396-1990"));
printf("\nPhone book after adding Zak Byers:\n");
print_phone_book(phone_book);
diff --git a/stc/cdefs.h b/stc/cdefs.h index 4f1a401b..82b411aa 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -79,14 +79,14 @@ for (ctype##_iter_t it = start, it##_end_ = finish; it.item != it##_end_.item; ctype##_next(&it))
#define c_items(...) __VA_ARGS__
-#define c_push(cnt_ptr, ctype, items) do { \
- const ctype##_input_t __arr[] = { items }; \
- ctype##_push_n(cnt_ptr, __arr, sizeof(__arr)/sizeof(__arr[0])); \
+#define c_push(self, ctype, items) do { \
+ const ctype##_input_t __arr[] = {items}; \
+ ctype##_push_n(self, __arr, sizeof(__arr)/sizeof(__arr[0])); \
} while (0)
-#define c_init(type, arr, init, n) do { \
- type __init = init, *__i = arr, *__last = __i + n; \
- while (__i != __last) = *__i++ = __init; \
+#define c_apply(array, type, value, n) do { \
+ type __val = value, *__i = array, *__last = __i + (n); \
+ while (__i != __last) = *__i++ = __val; \
} while (0)
#define c_destroy(ctype, ...) do { \
diff --git a/stc/clist.h b/stc/clist.h index 982a35d7..acffba6a 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -86,12 +86,13 @@ #define clist_ini {NULL}
#define clist_empty(list) ((list).last == NULL)
-#define clist_emplace_after(X, self, pos, items) do { \
- clist_##X* __self = self; \
- clist_##X##_iter_t __pos = pos; \
- const clist_##X##_input_t __arr[] = {items}; \
+
+#define c_emplace_after(self, ctype, pos, items) do { \
+ ctype* __self = self; \
+ ctype##_iter_t __pos = pos; \
+ const ctype##_input_t __arr[] = {items}; \
for (size_t __i=0; __i<sizeof(__arr)/sizeof(__arr[0]); ++__i) \
- __pos = clist_##X##_emplace_after(__self, __pos, __arr[__i]); \
+ __pos = ctype##_emplace_after(__self, __pos, __arr[__i]); \
} while (0)
declare_clist_types(void, int);
@@ -60,9 +60,10 @@ int main(void) { #define cset_ini cmap_ini
#define cset_size(s) cmap_size(s)
#define cset_bucket_count(s) cmap_bucket_count(s)
-#define cmap_try_emplace(X, self, k, v) do { \
- cmap_##X##_result_t __r = cmap_##X##_insert_key_(self, k); \
- if (__r.inserted) __r.item->value = v; \
+
+#define c_try_emplace(self, ctype, key, val) do { \
+ ctype##_result_t __r = ctype##_insert_key_(self, key); \
+ if (__r.inserted) __r.item->value = val; \
} while (false)
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
@@ -84,7 +84,7 @@ cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t last); \
\
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_insert_items(cvec_##X* self, size_t idx, Value* pfirst, Value* plast) { \
+ cvec_##X##_insert_range_ptr(cvec_##X* self, size_t idx, Value* pfirst, Value* plast) { \
cvec_##X##_iter_t pos = {self->data + idx}, first = {pfirst}, last = {plast}; \
return cvec_##X##_insert_range(self, pos, first, last); \
} \
@@ -94,7 +94,7 @@ return cvec_##X##_insert_range(self, pos, first, last); \
} \
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_insert_at(cvec_##X* self, size_t idx, Value value) { \
+ cvec_##X##_insert_at_idx(cvec_##X* self, size_t idx, Value value) { \
cvec_##X##_iter_t pos = {self->data + idx}, first = {&value}, last = {&value + 1}; \
return cvec_##X##_insert_range(self, pos, first, last); \
} \
@@ -103,8 +103,8 @@ cvec_##X##_insert(self, pos, valueFromRaw(rawValue)); \
} \
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_emplace_at(cvec_##X* self, size_t idx, RawValue rawValue) { \
- cvec_##X##_insert_at(self, idx, valueFromRaw(rawValue)); \
+ cvec_##X##_emplace_at_idx(cvec_##X* self, size_t idx, RawValue rawValue) { \
+ cvec_##X##_insert_at_idx(self, idx, valueFromRaw(rawValue)); \
} \
\
STC_API cvec_##X##_iter_t \
@@ -116,12 +116,12 @@ return cvec_##X##_erase_range(self, pos, next); \
} \
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_erase_at(cvec_##X* self, size_t idx) { \
+ cvec_##X##_erase_at_idx(cvec_##X* self, size_t idx) { \
cvec_##X##_iter_t first = {self->data + idx}, last = {first.item + 1}; \
return cvec_##X##_erase_range(self, first, last); \
} \
STC_INLINE cvec_##X##_iter_t \
- cvec_##X##_erase_items(cvec_##X* self, size_t ifirst, size_t ilast) { \
+ cvec_##X##_erase_range_idx(cvec_##X* self, size_t ifirst, size_t ilast) { \
cvec_##X##_iter_t first = {self->data + ifirst}, last = {self->data + ilast}; \
return cvec_##X##_erase_range(self, first, last); \
} \
|
