From a4e2ee22fd57665d2388d5debc17db896a4a389f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 3 Sep 2020 12:59:41 +0200 Subject: Changed constant _init to _ini to avoid conflict with _init() method. Reverted name cprique back to cpqueue. --- examples/README.md | 2 +- examples/advanced.c | 2 +- examples/benchmark.c | 2 +- examples/birthday.c | 2 +- examples/complex.c | 6 +++--- examples/demos.c | 14 +++++++------- examples/ex_gaussian.c | 6 +++--- examples/geek1.c | 2 +- examples/geek2.c | 4 ++-- examples/geek3.c | 4 ++-- examples/geek4.c | 12 ++++++------ examples/geek5.c | 4 ++-- examples/geek6.c | 2 +- examples/geek7.c | 16 ++++++++-------- examples/heap.c | 18 +++++++++--------- examples/inits.c | 14 +++++++------- examples/list.c | 2 +- examples/mapmap.c | 4 ++-- examples/phonebook.c | 2 +- examples/priority.c | 18 +++++++++--------- examples/random.c | 2 +- examples/stack.c | 5 ++++- examples/words.c | 6 +++--- 23 files changed, 76 insertions(+), 73 deletions(-) (limited to 'examples') diff --git a/examples/README.md b/examples/README.md index 661f7555..7947f16c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -60,7 +60,7 @@ cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() Finally, main which also demos the generic c_push() of multiple elements: ``` int main() { - cmap_vk vikings = cmap_init; + cmap_vk vikings = cmap_ini; c_push(&vikings, cmap_vk, c_items( { {"Einar", "Norway"}, 20 }, { {"Olaf", "Denmark"}, 24 }, diff --git a/examples/advanced.c b/examples/advanced.c index 03baf5fc..90f800e0 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -62,7 +62,7 @@ declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, int main() { - cmap_vk vikings = cmap_init; + cmap_vk vikings = cmap_ini; c_push(&vikings, cmap_vk, c_items( {{"Einar", "Norway"}, 20}, {{"Olaf", "Denmark"}, 24}, diff --git a/examples/benchmark.c b/examples/benchmark.c index d4e1e82c..1c94397d 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -34,7 +34,7 @@ crand_rng64_t rng; #define RAND(N) (crand_i64(&rng) & ((1 << N) - 1)) -#define CMAP_SETUP(tt, Key, Value) cmap_##tt map = cmap_init \ +#define CMAP_SETUP(tt, Key, Value) cmap_##tt map = cmap_ini \ ; cmap_##tt##_set_load_factors(&map, max_load_factor, 0.0) #define CMAP_PUT(tt, key, val) cmap_##tt##_put(&map, key, val)->value #define CMAP_INSERT(tt, key, val) cmap_##tt##_insert(&map, key, val) diff --git a/examples/birthday.c b/examples/birthday.c index 4f6e7a8b..be2114da 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_ini; cmap_ic_reserve(&m, N); clock_t now = clock(); for (size_t i = 0; i < N; ++i) { diff --git a/examples/complex.c b/examples/complex.c index 8810bac5..25a59eff 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_ini; { // Construct. carray2f table = carray2f_make(ydim, xdim, 0.f); printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table)); - clist_y tableList = clist_init; + clist_y tableList = clist_ini; // Put in some data. - cmap_g listMap = cmap_init; + cmap_g listMap = cmap_ini; *carray2f_at(&table, y, x) = 3.1415927; // table[y][x] clist_y_push_back(&tableList, table); diff --git a/examples/demos.c b/examples/demos.c index 731197e3..6b2806fa 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -39,7 +39,7 @@ declare_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1() { printf("\nVECTORDEMO1\n"); - cvec_ix bignums = cvec_init; // = (cvec_ix) cvec_init; if initializing after declaration. + cvec_ix bignums = cvec_ini; // = (cvec_ix) cvec_ini; if initializing after declaration. cvec_ix_reserve(&bignums, 100); for (size_t i = 0; i<=100; ++i) cvec_ix_push_back(&bignums, i * i * i); @@ -60,7 +60,7 @@ declare_cvec_str(); void vectordemo2() { printf("\nVECTORDEMO2\n"); - cvec_str names = cvec_init; + cvec_str names = cvec_ini; cvec_str_push_back(&names, "Mary"); cvec_str_push_back(&names, "Joe"); cvec_str_push_back(&names, "Chris"); @@ -78,7 +78,7 @@ declare_clist(ix, int); void listdemo1() { printf("\nLISTDEMO1\n"); - clist_ix nums = clist_init, nums2 = clist_init; + clist_ix nums = clist_ini, nums2 = clist_ini; for (int i = 0; i < 10; ++i) clist_ix_push_back(&nums, i); for (int i = 100; i < 110; ++i) @@ -105,7 +105,7 @@ declare_cset(i, int); void setdemo1() { printf("\nSETDEMO1\n"); - cset_i nums = cset_init; + cset_i nums = cset_ini; cset_i_put(&nums, 8); cset_i_put(&nums, 11); @@ -120,7 +120,7 @@ declare_cmap(ii, int, int); void mapdemo1() { printf("\nMAPDEMO1\n"); - cmap_ii nums = cmap_init; + cmap_ii nums = cmap_ini; cmap_ii_put(&nums, 8, 64); cmap_ii_put(&nums, 11, 121); @@ -134,7 +134,7 @@ declare_cmap_strkey(si, int); // Shorthand macro for the general declare_cmap ex void mapdemo2() { printf("\nMAPDEMO2\n"); - cmap_si nums = cmap_init; + cmap_si nums = cmap_ini; cmap_si_put(&nums, "Hello", 64); cmap_si_put(&nums, "Groovy", 121); cmap_si_put(&nums, "Groovy", 200); // overwrite previous @@ -156,7 +156,7 @@ declare_cmap_strkey(ss, cstr_t, cstr_destroy); void mapdemo3() { printf("\nMAPDEMO3\n"); - cmap_ss table = cmap_init; + cmap_ss table = cmap_ini; cmap_ss_put(&table, "Map", cstr_make("test")); cmap_ss_put(&table, "Make", cstr_make("my")); cmap_ss_put(&table, "Sunny", cstr_make("day")); diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 75efec51..a4682a2b 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -29,20 +29,20 @@ int main() crand_normal_f64_t dist = crand_normal_f64_init(rng, Mean, StdDev); // Create histogram map - cmap_i mhist = cmap_init; + cmap_i mhist = cmap_ini; for (size_t i = 0; i < N; ++i) { int index = round( crand_normal_f64(&dist) ); cmap_i_insert(&mhist, index, 0)->value += 1; } // Transfer map to vec and sort it by map keys. - cvec_e vhist = cvec_init; + cvec_e vhist = cvec_ini; c_foreach (i, cmap_i, mhist) cvec_e_push_back(&vhist, *i.item); cvec_e_sort(&vhist); // Print the gaussian bar chart - cstr_t bar = cstr_init; + cstr_t bar = cstr_ini; c_foreach (i, cvec_e, vhist) { size_t n = (size_t) (i.item->value * Mag / N); if (n > 0) { diff --git a/examples/geek1.c b/examples/geek1.c index 44824978..8759e143 100644 --- a/examples/geek1.c +++ b/examples/geek1.c @@ -19,7 +19,7 @@ int findMaximumPairs(int a[], int n, int k) { // Hash-table - cmap_ii hash = cmap_init; + cmap_ii hash = cmap_ini; for (int i = 0; i < n; i++) { cmap_ii_insert(&hash, a[i] % k, 0)->value++; } diff --git a/examples/geek2.c b/examples/geek2.c index 6141518f..0e8b384a 100644 --- a/examples/geek2.c +++ b/examples/geek2.c @@ -10,8 +10,8 @@ int main() { // Lets use an explicit type signature (which would // be `cmap` in this example). - cmap_str book_reviews = cmap_init; - cset_str set = cset_init; + cmap_str book_reviews = cmap_ini; + cset_str set = cset_ini; cset_str_put(&set, "Hello"); cset_str_put(&set, "You"); cset_str_put(&set, "Tube"); diff --git a/examples/geek3.c b/examples/geek3.c index ad2bdfa1..044d7b16 100644 --- a/examples/geek3.c +++ b/examples/geek3.c @@ -8,7 +8,7 @@ declare_cmap_strkey(ss, cstr_t, cstr_destroy); int main () { - cmap_si mymap = cmap_init; + cmap_si mymap = cmap_ini; cmap_si_put(&mymap, "Mars", 3000); cmap_si_put(&mymap, "Saturn", 60000); cmap_si_put(&mymap, "Jupiter", 70000); @@ -28,7 +28,7 @@ int main () puts("------------------------"); // Create an unordered_map of three strings (that map to strings) - cmap_ss u = cmap_init; + cmap_ss u = cmap_ini; cmap_ss_put(&u, "RED", cstr_make("#FF0000")); cmap_ss_put(&u, "GREEN", cstr_make("#00FF00")); cmap_ss_put(&u, "BLUE", cstr_make("#0000FF")); diff --git a/examples/geek4.c b/examples/geek4.c index a62a6fd1..06c93de4 100644 --- a/examples/geek4.c +++ b/examples/geek4.c @@ -49,7 +49,7 @@ int commonWords(cvec_str S) // To store all the words of first string - cvec_sb ans = cvec_init; + cvec_sb ans = cvec_ini; // m will store number of strings in given vector m = cvec_size(S); @@ -59,8 +59,8 @@ int commonWords(cvec_str S) // Extract all words of first string and store it in ans while (i < cstr_size(S.data[0])) { // To store separate words - cstr_t word = cstr_init; - cmap_sb_entry_t tmp = {cstr_init, false}; + cstr_t word = cstr_ini; + cmap_sb_entry_t tmp = {cstr_ini, false}; while (i < cstr_size(S.data[0]) && S.data[0].str[i] != ' ') { cstr_push_back(&word, S.data[0].str[i]); @@ -85,11 +85,11 @@ int commonWords(cvec_str S) for (j = 1; j < m; j++) { // It will be used to check if a word is present // in a particuler string - cmap_sb has = cmap_init; + cmap_sb has = cmap_ini; i = 0; while (i < cstr_size(S.data[j])) { - cstr_t word = cstr_init; + cstr_t word = cstr_ini; while (i < cstr_size(S.data[j]) && S.data[j].str[i] != ' ') { cstr_push_back(&word, S.data[j].str[i]); i++; @@ -136,7 +136,7 @@ int commonWords(cvec_str S) // Driver code int main() { - cvec_str S = cvec_init; + cvec_str S = cvec_ini; cvec_str_push_back(&S, "there is a cow"); cvec_str_push_back(&S, "cow is our mother"); cvec_str_push_back(&S, "cow gives us milk and milk is sweet"); diff --git a/examples/geek5.c b/examples/geek5.c index a0531ad3..614bc387 100644 --- a/examples/geek5.c +++ b/examples/geek5.c @@ -29,7 +29,7 @@ declare_cmap_strkey(sv, cvec_i, cvec_i_destroy); int NumOccurrences(const char* arr[], int n, const char* str, int L, int R) { // To store the indices of strings in the array - cmap_sv M = cmap_init; + cmap_sv M = cmap_ini; for (int i = 0; i < n; i++) { const char* temp = arr[i]; cmap_sv_entry_t *it = cmap_sv_find(&M, temp); @@ -38,7 +38,7 @@ int NumOccurrences(const char* arr[], int n, const char* str, int L, int R) // have an entry in the map // then create the entry if (it == NULL) { - cvec_i A = cvec_init; + cvec_i A = cvec_ini; cvec_i_push_back(&A, i + 1); cmap_sv_put(&M, temp, A); } diff --git a/examples/geek6.c b/examples/geek6.c index db0b3bcf..e906600f 100644 --- a/examples/geek6.c +++ b/examples/geek6.c @@ -37,7 +37,7 @@ declare_cset(i, int); int missingNumber(int a[], int n) { // Declaring an unordered_map - cset_i mp = cset_init; + cset_i mp = cset_ini; // if array value is positive // store it in map diff --git a/examples/geek7.c b/examples/geek7.c index c686b014..4be984ee 100644 --- a/examples/geek7.c +++ b/examples/geek7.c @@ -25,11 +25,11 @@ After inserting all the elements excluding the ones which are to be deleted, Pop #include #include #include -#include +#include declare_cmap(ii, int, int); declare_cvec(i, int); -declare_cprique(i, cvec_i, >); +declare_cpqueue(i, cvec_i, >); // Find k minimum element from arr[0..m-1] after deleting // elements from del[0..n-1] @@ -37,14 +37,14 @@ void findElementsAfterDel(int arr[], int m, int del[], int n, int k) { // Hash Map of the numbers to be deleted - cmap_ii mp = cmap_init; + cmap_ii mp = cmap_ini; for (int i = 0; i < n; ++i) { // Increment the count of del[i] cmap_ii_insert(&mp, del[i], 0)->value++; } - cprique_i heap = cprique_i_init(); + cpqueue_i heap = cpqueue_i_init(); for (int i = 0; i < m; ++i) { @@ -63,17 +63,17 @@ void findElementsAfterDel(int arr[], int m, int del[], // Else push it in the min heap else - cprique_i_push(&heap, arr[i]); + cpqueue_i_push(&heap, arr[i]); } // Print top k elements in the min heap for (int i = 0; i < k; ++i) { - printf("%d ", *cprique_i_top(&heap)); + printf("%d ", *cpqueue_i_top(&heap)); // Pop the top element - cprique_i_pop(&heap); + cpqueue_i_pop(&heap); } - cprique_i_destroy(&heap); + cpqueue_i_destroy(&heap); } int main() diff --git a/examples/heap.c b/examples/heap.c index fbcef0cd..5917dd30 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -2,10 +2,10 @@ #include #include #include -#include +#include declare_cvec(f, float); -declare_cprique(f, cvec_f, >); +declare_cpqueue(f, cvec_f, >); int main() { @@ -13,33 +13,33 @@ int main() crand_rng32_t pcg; int N = 3000000, M = 100; - cprique_f pq = cprique_f_init(); + cpqueue_f pq = cpqueue_f_init(); pcg = crand_rng32_init(seed); clock_t start = clock(); for (int i=0; i #include #include -#include +#include #include declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t @@ -17,7 +17,7 @@ declare_cvec(ip, ipair_t, c_default_destroy, ipair_compare); declare_clist(ip, ipair_t, c_default_destroy, ipair_compare); declare_cvec(f, float); -declare_cprique(f, cvec_f, >); +declare_cpqueue(f, cvec_f, >); int main(void) { @@ -31,16 +31,16 @@ int main(void) { // CVEC PRIORITY QUEUE - cprique_f_build(&floats); // reorganise vec - c_push(&floats, cprique_f, c_items(40.0f, 20.0f, 50.0f, 30.0f, 10.0f)); + cpqueue_f_build(&floats); // reorganise vec + c_push(&floats, cpqueue_f, c_items(40.0f, 20.0f, 50.0f, 30.0f, 10.0f)); // sorted: while (cvec_size(floats) > 0) { - printf("%.1f ", *cprique_f_top(&floats)); - cprique_f_pop(&floats); + printf("%.1f ", *cpqueue_f_top(&floats)); + cpqueue_f_pop(&floats); } puts("\n"); - cprique_f_destroy(&floats); + cpqueue_f_destroy(&floats); // CMAP ID diff --git a/examples/list.c b/examples/list.c index 3aff4482..3b46f02b 100644 --- a/examples/list.c +++ b/examples/list.c @@ -6,7 +6,7 @@ declare_clist(fx, double); int main() { int k, n = 100000; - clist_fx list = clist_init; + clist_fx list = clist_ini; crand_rng64_t eng = crand_rng64_init(time(NULL)); crand_uniform_f64_t dist = crand_uniform_f64_init(eng, 0.0f, n); diff --git a/examples/mapmap.c b/examples/mapmap.c index d0d8c8fa..a0c1b173 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -7,8 +7,8 @@ declare_cmap_str(); declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy); int main(void) { - cmap_cfg config = cmap_init; - cmap_str init = cmap_init; + cmap_cfg config = cmap_ini; + cmap_str init = cmap_ini; cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "name", "Joe"); cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "groups", "proj1,proj3"); cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj1", "Energy"); diff --git a/examples/phonebook.c b/examples/phonebook.c index 15df04e3..d2ed227f 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_ini; c_push(&phone_book, cmap_str, c_items( {"Lilia Friedman", "(892) 670-4739"}, {"Tariq Beltran", "(489) 600-7575"}, diff --git a/examples/priority.c b/examples/priority.c index fc0526bf..82e78621 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -2,34 +2,34 @@ #include #include #include -#include +#include #include #include declare_cvec(i, int64_t); -declare_cprique(i, cvec_i, >); // min-heap (increasing values) +declare_cpqueue(i, cvec_i, >); // min-heap (increasing values) int main() { size_t N = 10000000; crand_rng64_t pcg = crand_rng64_init(time(NULL)); crand_uniform_i64_t dist = crand_uniform_i64_init(pcg, 0, N * 10); - cprique_i heap = cprique_i_init(); + cpqueue_i heap = cpqueue_i_init(); // Push ten million random numbers to priority queue for (int i=0; i= 0 && n < R) ++hist[n]; } - cstr_t bar = cstr_init; + cstr_t bar = cstr_ini; for (int i=0; i < R; ++i) { cstr_take(&bar, cstr_with_size(hist[i] * 25ull * R / N2, '*')); printf("%2d %s\n", i, bar.str); diff --git a/examples/stack.c b/examples/stack.c index 321228a2..de30c5b4 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -1,12 +1,15 @@ -#include #include +#include +#include declare_cvec(i, int); declare_cstack(i, cvec_i); +declare_cstack(c, cstr); int main() { cstack_i stack = cstack_i_init(); + cstack_c chars = cstack_c_init(); for (int i=0; i<100; ++i) cstack_i_push(&stack, i*i); diff --git a/examples/words.c b/examples/words.c index 98134cf6..275ffee7 100644 --- a/examples/words.c +++ b/examples/words.c @@ -11,7 +11,7 @@ declare_cmap_strkey(si, int); int main1() { - clist_str lwords = clist_init; + clist_str lwords = clist_ini; c_push(&lwords, clist_str, c_items( "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" @@ -21,13 +21,13 @@ int main1() printf("%s\n", w.item->value.str); puts(""); - cvec_str words = cvec_init; + cvec_str words = cvec_ini; c_push(&words, cvec_str, c_items( "this", "sentence", "is", "not", "a", "sentence", "this", "sentence", "is", "a", "hoax" )); - cmap_si word_map = cmap_init; + cmap_si word_map = cmap_ini; c_foreach (w, cvec_str, words) ++cmap_si_insert(&word_map, w.item->str, 0)->value; -- cgit v1.2.3