From 7171182ce7e0106f8f0fc47ed8f1fe1f58b2ea5d Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 2 Nov 2020 12:24:32 +0100 Subject: Changed (half)-internal *_INIT to *__init macros. Minor reformatting. --- examples/README.md | 2 +- examples/advanced.c | 2 +- examples/benchmark.c | 7 +++---- examples/birthday.c | 2 +- examples/complex.c | 6 +++--- examples/demos.c | 22 +++++++++++----------- examples/inits.c | 20 +++++++------------- examples/list.c | 2 +- examples/mapmap.c | 4 ++-- examples/phonebook.c | 2 +- examples/words.c | 6 +++--- 11 files changed, 34 insertions(+), 41 deletions(-) (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index 4c24d32a..114f6aac 100644 --- a/examples/README.md +++ b/examples/README.md @@ -58,7 +58,7 @@ using_cmap(vk, Viking, int, c_default_del, vikingraw_equals, vikingraw_hash, cmap_vk uses vikingraw_hash() for hash value calculations, and vikingraw_equals() for equality test. cmap_vk_del() will free all memory allocated for Viking keys and the hash table values. Finally, main which also demos the generic c_push_items() of multiple elements: ```C int main() { - cmap_vk vikings = cmap_INIT; + cmap_vk vikings = cmap_vk_init(); c_push_items(&vikings, cmap_vk, { { {"Einar", "Norway"}, 20}, { {"Olaf", "Denmark"}, 24}, diff --git a/examples/advanced.c b/examples/advanced.c index 83155405..d559e154 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -60,7 +60,7 @@ using_cmap(vk, Viking, int, c_default_del, vikingvw_equals, vikingvw_hash, int main() { - cmap_vk vikings = cmap_INIT; + cmap_vk vikings = cmap_vk_init(); c_push_items(&vikings, cmap_vk, { {{"Einar", "Norway"}, 20}, {{"Olaf", "Denmark"}, 24}, diff --git a/examples/benchmark.c b/examples/benchmark.c index f831f417..419e7a8f 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -1,11 +1,10 @@ +#include +#include #include #include #include #include "others/khash.h" -#include -#include - #ifdef __cplusplus #include #include "others/bytell_hash_map.hpp" @@ -34,7 +33,7 @@ crand_rng64_t rng; #define RAND(N) (crand_i64(&rng) & ((1 << N) - 1)) -#define CMAP_SETUP(X, Key, Value) cmap_##X map = cmap_INIT \ +#define CMAP_SETUP(X, Key, Value) cmap_##X map = cmap__init \ ; cmap_##X##_set_load_factors(&map, max_load_factor, 0.0) #define CMAP_PUT(X, key, val) cmap_##X##_put(&map, key, val).first->second #define CMAP_EMPLACE(X, key, val) cmap_##X##_emplace(&map, key, val) diff --git a/examples/birthday.c b/examples/birthday.c index bd3c85f3..fd7f9f46 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -16,7 +16,7 @@ const static uint64_t mask = (1ull << 52) - 1; void repeats(void) { crand_rng64_t rng = crand_rng64_init(seed); - cmap_ic m = cmap_INIT; + cmap_ic m = cmap_ic_init(); cmap_ic_reserve(&m, N); clock_t now = clock(); c_forrange (i, N) { diff --git a/examples/complex.c b/examples/complex.c index db22f235..ff97c141 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -14,14 +14,14 @@ int main() { int xdim = 4, ydim = 6; int x = 1, y = 5, tableKey = 42; const char* strKey = "first"; - cmap_s myMap = cmap_INIT; + cmap_s myMap = cmap__init; { // Construct. carray2f table = carray2f_init(ydim, xdim, 0.f); c_print(1, "table: ({}, {})\n", carray2_ydim(table), carray2_xdim(table)); - clist_y tableList = clist_INIT; + clist_y tableList = clist__init; // Put in some data. - cmap_g listMap = cmap_INIT; + cmap_g listMap = cmap__init; *carray2f_at(&table, y, x) = 3.1415927f; // table[y][x] clist_y_push_back(&tableList, table); diff --git a/examples/demos.c b/examples/demos.c index 16d77319..580942f1 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -39,15 +39,15 @@ using_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1() { c_print(1, "\nVECTORDEMO1\n"); - cvec_ix bignums = cvec_INIT; // = (cvec_ix) cvec_INIT; if initializing after declaration. + cvec_ix bignums = cvec__init; // = (cvec_ix) cvec__init; if initializing after declaration. cvec_ix_reserve(&bignums, 100); - for (size_t i = 0; i<=100; ++i) + c_forrange (i, 101) cvec_ix_push_back(&bignums, i * i * i); c_print(1, "erase - {}: {}\n", 100, bignums.data[100]); cvec_ix_pop_back(&bignums); // erase the last - for (size_t i = 0; i < cvec_size(bignums); ++i) { + c_forrange (i, cvec_size(bignums)) { if (i >= 90) c_print(1, "{}: {}\n", i, bignums.data[i]); } cvec_ix_del(&bignums); @@ -60,7 +60,7 @@ using_cvec_str(); void vectordemo2() { c_print(1, "\nVECTORDEMO2\n"); - cvec_str names = cvec_INIT; + cvec_str names = cvec__init; cvec_str_emplace_back(&names, "Mary"); cvec_str_emplace_back(&names, "Joe"); cvec_str_emplace_back(&names, "Chris"); @@ -78,10 +78,10 @@ using_clist(ix, int); void listdemo1() { c_print(1, "\nLISTDEMO1\n"); - clist_ix nums = clist_INIT, nums2 = clist_INIT; - for (int i = 0; i < 10; ++i) + clist_ix nums = clist__init, nums2 = clist__init; + c_forrange (i, 10) clist_ix_push_back(&nums, i); - for (int i = 100; i < 110; ++i) + c_forrange (i, int, 100, 110) clist_ix_push_back(&nums2, i); c_foreach (i, clist_ix, nums) c_print(1, "value: {}\n", *i.val); @@ -105,7 +105,7 @@ using_cset(i, int); void setdemo1() { c_print(1, "\nSETDEMO1\n"); - cset_i nums = cset_INIT; + cset_i nums = cset__init; cset_i_insert(&nums, 8); cset_i_insert(&nums, 11); @@ -120,7 +120,7 @@ using_cmap(ii, int, int); void mapdemo1() { c_print(1, "\nMAPDEMO1\n"); - cmap_ii nums = cmap_INIT; + cmap_ii nums = cmap__init; cmap_ii_put(&nums, 8, 64); cmap_ii_put(&nums, 11, 121); c_print(1, "val 8: {}\n", *cmap_ii_at(&nums, 8)); @@ -133,7 +133,7 @@ using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expans void mapdemo2() { c_print(1, "\nMAPDEMO2\n"); - cmap_si nums = cmap_INIT; + cmap_si nums = cmap__init; cmap_si_put(&nums, "Hello", 64); cmap_si_put(&nums, "Groovy", 121); cmap_si_put(&nums, "Groovy", 200); // overwrite previous @@ -155,7 +155,7 @@ using_cmap_str(); void mapdemo3() { c_print(1, "\nMAPDEMO3\n"); - cmap_str table = cmap_INIT; + cmap_str table = cmap__init; cmap_str_put(&table, "Map", "test"); cmap_str_put(&table, "Make", "my"); cmap_str_put(&table, "Sunny", "day"); diff --git a/examples/inits.c b/examples/inits.c index 9436310e..42be17fb 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -23,7 +23,7 @@ int main(void) { // CVEC FLOAT / PRIORITY QUEUE - cvec_f floats = cvec_INIT; + cvec_f floats = cvec__init; c_push_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f}); c_foreach (i, cvec_f, floats) c_print(1, "{:.1f} ", *i.val); @@ -45,7 +45,7 @@ int main(void) // CMAP ID int year = 2020; - cmap_id idnames = cmap_INIT; + cmap_id idnames = cmap__init; c_push_items(&idnames, cmap_id, { {100, cstr_from("Hello")}, {110, cstr_from("World")}, @@ -59,7 +59,7 @@ int main(void) // CMAP CNT - cmap_cnt countries = cmap_INIT; + cmap_cnt countries = cmap__init; c_push_items(&countries, cmap_cnt, { {"Norway", 100}, {"Denmark", 50}, @@ -82,12 +82,9 @@ int main(void) // CVEC PAIR - cvec_ip pairs1 = cvec_INIT; + cvec_ip pairs1 = cvec__init; c_push_items(&pairs1, cvec_ip, { - {5, 6}, - {3, 4}, - {1, 2}, - {7, 8}, + {5, 6}, {3, 4}, {1, 2}, {7, 8}, }); cvec_ip_sort(&pairs1); @@ -98,12 +95,9 @@ int main(void) // CLIST PAIR - clist_ip pairs2 = clist_INIT; + clist_ip pairs2 = clist__init; c_push_items(&pairs2, clist_ip, { - {5, 6}, - {3, 4}, - {1, 2}, - {7, 8}, + {5, 6}, {3, 4}, {1, 2}, {7, 8}, }); clist_ip_sort(&pairs2); diff --git a/examples/list.c b/examples/list.c index 84a13bf5..bdac3ef0 100644 --- a/examples/list.c +++ b/examples/list.c @@ -9,7 +9,7 @@ int main() { int k; const int n = 2000000; - clist_fx list = clist_INIT; + clist_fx list = clist__init; crand_rng64_t eng = crand_rng64_init(1234); crand_uniform_f64_t dist = crand_uniform_f64_init(100.0f, n); int m = 0; diff --git a/examples/mapmap.c b/examples/mapmap.c index 4e6c2f1a..0e4b6991 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -7,8 +7,8 @@ using_cmap_str(); using_cmap_strkey(cfg, cmap_str, cmap_str_del); int main(void) { - cmap_cfg config = cmap_INIT; - cmap_str init = cmap_INIT; + cmap_cfg config = cmap__init; + cmap_str init = cmap__init; cmap_str_put(&cmap_cfg_emplace(&config, "user", init).first->second, "name", "Joe"); cmap_str_put(&cmap_cfg_emplace(&config, "user", init).first->second, "groups", "proj1,proj3"); cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj1", "Energy"); diff --git a/examples/phonebook.c b/examples/phonebook.c index e567c442..a1249ae5 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -36,7 +36,7 @@ void print_phone_book(cmap_str phone_book) int main(int argc, char **argv) { bool erased; - cmap_str phone_book = cmap_INIT; + cmap_str phone_book = cmap__init; c_push_items(&phone_book, cmap_str, { {"Lilia Friedman", "(892) 670-4739"}, {"Tariq Beltran", "(489) 600-7575"}, diff --git a/examples/words.c b/examples/words.c index b72251c6..3ee285e8 100644 --- a/examples/words.c +++ b/examples/words.c @@ -11,7 +11,7 @@ using_cmap_strkey(si, int); int main1() { - clist_str lwords = clist_INIT; + clist_str lwords = clist__init; c_push_items(&lwords, clist_str, { "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" @@ -21,13 +21,13 @@ int main1() c_print(1, "{}\n", w.val->str); puts(""); - cvec_str words = cvec_INIT; + cvec_str words = cvec__init; c_push_items(&words, cvec_str, { "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" }); - cmap_si word_map = cmap_INIT; + cmap_si word_map = cmap__init; c_foreach (w, cvec_str, words) cmap_si_emplace(&word_map, w.val->str, 0).first->second += 1; -- cgit v1.2.3