summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-14 13:17:39 +0200
committerTyge Løvset <[email protected]>2020-09-14 13:17:39 +0200
commit131c47066cba5a8b59d5889415761d0300068bdc (patch)
tree50af1ab74d6cd2616d9b797aaef71f1aea4de8cf
parentab21f83c4af4f2b628ce36ad03f5c78fbb11a06a (diff)
downloadSTC-modified-131c47066cba5a8b59d5889415761d0300068bdc.tar.gz
STC-modified-131c47066cba5a8b59d5889415761d0300068bdc.zip
Got rid of c_items() macro.
-rw-r--r--README.md2
-rw-r--r--examples/README.md4
-rw-r--r--examples/advanced.c4
-rw-r--r--examples/geek2.c4
-rw-r--r--examples/inits.c20
-rw-r--r--examples/list.c2
-rw-r--r--examples/phonebook.c4
-rw-r--r--examples/priority.c2
-rw-r--r--examples/words.c8
-rw-r--r--stc/cdefs.h5
-rw-r--r--stc/clist.h4
-rw-r--r--stc/cmap.h13
12 files changed, 37 insertions, 35 deletions
diff --git a/README.md b/README.md
index 4aeff7ae..7f672e92 100644
--- a/README.md
+++ b/README.md
@@ -300,7 +300,7 @@ int main() {
clist_fx_clear(&list);
// generic c_push() function, works on most containers:
- c_push(&list, clist_fx, c_items(10, 20, 30, 40, 50));
+ c_push(&list, clist_fx, {10, 20, 30, 40, 50});
c_foreach (i, clist_fx, list)
printf("%f ", i.item->value);
diff --git a/examples/README.md b/examples/README.md
index 0cdefd55..26eb4bb1 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -61,11 +61,11 @@ Finally, main which also demos the generic c_push() of multiple elements:
```
int main() {
cmap_vk vikings = cmap_ini;
- c_push(&vikings, cmap_vk, c_items(
+ c_push(&vikings, cmap_vk, {
{ {"Einar", "Norway"}, 20 },
{ {"Olaf", "Denmark"}, 24 },
{ {"Harald", "Iceland"}, 12 },
- ));
+ });
VikingVw look = {"Einar", "Norway"};
cmap_vk_entry_t *e = cmap_vk_find(&vikings, look);
e->value += 5; // update
diff --git a/examples/advanced.c b/examples/advanced.c
index 0aa1600e..d3c1ca21 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -62,11 +62,11 @@ declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
int main()
{
cmap_vk vikings = cmap_ini;
- c_push(&vikings, cmap_vk, c_items(
+ c_push(&vikings, cmap_vk, {
{{"Einar", "Norway"}, 20},
{{"Olaf", "Denmark"}, 24},
{{"Harald", "Iceland"}, 12},
- ));
+ });
VikingVw einar = {"Einar", "Norway"};
cmap_vk_entry_t *e = cmap_vk_find(&vikings, einar);
diff --git a/examples/geek2.c b/examples/geek2.c
index c76d262f..a02ede25 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -20,12 +20,12 @@ int main()
puts("");
// Review some books.
- c_push(&book_reviews, cmap_str, c_items(
+ c_push(&book_reviews, cmap_str, {
{"Adventures of Huckleberry Finn", "My favorite book."},
{"Grimms' Fairy Tales", "Masterpiece."},
{"Pride and Prejudice", "Very enjoyable."},
{"The Adventures of Sherlock Holmes", "Eye lyked it alot."},
- ));
+ });
/*
cmap_str_emplace(&book_reviews,
"Adventures of Huckleberry Finn",
diff --git a/examples/inits.c b/examples/inits.c
index ebb2e0e1..5a0ae04b 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -25,7 +25,7 @@ int main(void) {
// CVEC FLOAT / PRIORITY QUEUE
cvec_f floats = cvec_ini;
- c_push(&floats, cvec_f, c_items(4.0f, 2.0f, 5.0f, 3.0f, 1.0f));
+ c_push(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
c_foreach (i, cvec_f, floats) printf("%.1f ", *i.item);
puts("");
@@ -33,7 +33,7 @@ int main(void) {
// CVEC PRIORITY QUEUE
cpqueue_f_build(&floats); // reorganise vec
- c_push(&floats, cpqueue_f, c_items(40.0f, 20.0f, 50.0f, 30.0f, 10.0f));
+ c_push(&floats, cpqueue_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
// sorted:
while (cvec_size(floats) > 0) {
@@ -47,11 +47,11 @@ int main(void) {
int year = 2020;
cmap_id idnames = cmap_ini;
- c_push(&idnames, cmap_id, c_items(
+ c_push(&idnames, cmap_id, {
{100, cstr_make("Hello")},
{110, cstr_make("World")},
{120, cstr_from("Howdy, -%d-", year)},
- ));
+ });
c_foreach (i, cmap_id, idnames)
printf("%d: %s\n", i.item->key, i.item->value.str);
@@ -61,7 +61,7 @@ int main(void) {
// CMAP CNT
cmap_cnt countries = cmap_ini;
- c_push(&countries, cmap_cnt, c_items(
+ c_push(&countries, cmap_cnt, {
{"Norway", 100},
{"Denmark", 50},
{"Iceland", 10},
@@ -70,7 +70,7 @@ int main(void) {
{"Germany", 10},
{"Spain", 10},
{"France", 10},
- ));
+ });
cmap_cnt_emplace(&countries, "Greenland", 0).item->value += 20;
cmap_cnt_emplace(&countries, "Sweden", 0).item->value += 20;
cmap_cnt_emplace(&countries, "Norway", 0).item->value += 20;
@@ -84,12 +84,12 @@ int main(void) {
// CVEC PAIR
cvec_ip pairs1 = cvec_ini;
- c_push(&pairs1, cvec_ip, c_items(
+ c_push(&pairs1, cvec_ip, {
{5, 6},
{3, 4},
{1, 2},
{7, 8},
- ));
+ });
cvec_ip_sort(&pairs1);
c_foreach (i, cvec_ip, pairs1)
@@ -100,12 +100,12 @@ int main(void) {
// CLIST PAIR
clist_ip pairs2 = clist_ini;
- c_push(&pairs2, clist_ip, c_items(
+ c_push(&pairs2, clist_ip, {
{5, 6},
{3, 4},
{1, 2},
{7, 8},
- ));
+ });
clist_ip_sort(&pairs2);
c_foreach (i, clist_ip, pairs2)
diff --git a/examples/list.c b/examples/list.c
index dd8bba2f..d140d103 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -23,7 +23,7 @@ int main() {
puts("");
clist_fx_clear(&list);
- c_push(&list, clist_fx, c_items(10, 20, 30, 40, 30, 50));
+ c_push(&list, clist_fx, {10, 20, 30, 40, 30, 50});
c_foreach (i, clist_fx, list) printf(" %g", i.item->value);
puts("");
diff --git a/examples/phonebook.c b/examples/phonebook.c
index 74105f25..983f4e74 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -37,12 +37,12 @@ int main(int argc, char **argv)
{
bool erased;
cmap_str phone_book = cmap_ini;
- c_push(&phone_book, cmap_str, c_items(
+ c_push(&phone_book, cmap_str, {
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
{"Laiba Juarez", "(303) 885-5692"},
{"Elliott Mooney", "(945) 616-4482"},
- ));
+ });
printf("Phone book:\n");
print_phone_book(phone_book);
diff --git a/examples/priority.c b/examples/priority.c
index e857761c..8bd2abce 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -20,7 +20,7 @@ int main() {
cpqueue_i_push(&heap, crand_uniform_i64(&pcg, &dist));
// push some negative numbers too.
- c_push(&heap, cpqueue_i, c_items(-231, -32, -873, -4, -343));
+ c_push(&heap, cpqueue_i, {-231, -32, -873, -4, -343});
for (int i=0; i<N; ++i)
cpqueue_i_push(&heap, crand_uniform_i64(&pcg, &dist));
diff --git a/examples/words.c b/examples/words.c
index 9e0fc0cc..09dd43dc 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -12,20 +12,20 @@ declare_cmap_strkey(si, int);
int main1()
{
clist_str lwords = clist_ini;
- c_push(&lwords, clist_str, c_items(
+ c_push(&lwords, clist_str, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
- ));
+ });
clist_str_push_back(&lwords, cstr_from("%f", 123897.0 / 23.0));
c_foreach (w, clist_str, lwords)
printf("%s\n", w.item->value.str);
puts("");
cvec_str words = cvec_ini;
- c_push(&words, cvec_str, c_items(
+ c_push(&words, cvec_str, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
- ));
+ });
cmap_si word_map = cmap_ini;
c_foreach (w, cvec_str, words)
diff --git a/stc/cdefs.h b/stc/cdefs.h
index bc7b0e1f..dc12b618 100644
--- a/stc/cdefs.h
+++ b/stc/cdefs.h
@@ -85,9 +85,8 @@
#define c_foreach_4(it, ctype, start, finish) \
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(self, ctype, items) do { \
- const ctype##_input_t __arr[] = {items}; \
+#define c_push(self, ctype, ...) do { \
+ const ctype##_input_t __arr[] = __VA_ARGS__; \
ctype##_push_n(self, __arr, sizeof(__arr)/sizeof(__arr[0])); \
} while (0)
diff --git a/stc/clist.h b/stc/clist.h
index 9743a022..baba7ed3 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -89,10 +89,10 @@
#define clist_ini {NULL}
#define clist_empty(list) ((list).last == NULL)
-#define c_emplace_after(self, ctype, pos, items) do { \
+#define c_emplace_after(self, ctype, pos, ...) do { \
ctype* __self = self; \
ctype##_iter_t __pos = pos; \
- const ctype##_input_t __arr[] = {items}; \
+ const ctype##_input_t __arr[] = __VA_ARGS__; \
for (size_t __i=0; __i<sizeof(__arr)/sizeof(__arr[0]); ++__i) \
__pos = ctype##_emplace_after(__self, __pos, __arr[__i]); \
} while (0)
diff --git a/stc/cmap.h b/stc/cmap.h
index 8fed0497..7b62efeb 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -65,6 +65,10 @@ int main(void) {
ctype##_result_t __r = ctype##_insert_key_(self, key); \
if (__r.inserted) __r.item->value = val; \
} while (0)
+#define c_insert(self, ctype, ...) do { \
+ const ctype##_input_t __arr[] = __VA_ARGS__; \
+ for (size_t i=0;i<sizeof(__arr)/sizeof(__arr[0]); ++i) ctype##_insert(self, __arr[i]); \
+} while (0)
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
#define chash_reduce(x, N) ((uint32_t) (((uint64_t) (x) * (N)) >> 32))
@@ -231,12 +235,11 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
CMAP_ONLY_##ctype( if (res.inserted) res.item->value = valueFromRaw(rawVal); ) \
return res; \
} \
-\
- CSET_ONLY_##ctype( \
STC_INLINE ctype##_##X##_result_t \
- ctype##_##X##_insert(ctype##_##X* self, RawKey rawKey) { \
- return ctype##_##X##_insert_key_(self, rawKey); \
- }) \
+ ctype##_##X##_insert(ctype##_##X* self, ctype##_##X##_input_t in) { \
+ return CSET_ONLY_##ctype(ctype##_##X##_insert_key_(self, in)) \
+ CMAP_ONLY_##ctype(ctype##_##X##_emplace(self, in.first, in.second)); \
+ } \
\
CMAP_ONLY_##ctype( \
STC_INLINE ctype##_##X##_result_t \