From 681873e4cb6ea076b79c6c70b2df2ba4e4c19bda Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 18 Sep 2020 11:55:29 +0200 Subject: Changed _ini macro constant to _INIT, and _destroy() to _del. --- README.md | 40 ++++++++++++++++++++-------------------- examples/README.md | 16 ++++++++-------- examples/advanced.c | 16 ++++++++-------- examples/benchmark.c | 6 +++--- examples/birthday.c | 2 +- examples/bits.c | 6 +++--- examples/complex.c | 18 +++++++++--------- examples/demos.c | 34 +++++++++++++++++----------------- examples/ex_gaussian.c | 14 +++++++------- examples/heap.c | 2 +- examples/inits.c | 26 +++++++++++++------------- examples/list.c | 4 ++-- examples/mapmap.c | 8 ++++---- examples/phonebook.c | 4 ++-- examples/prime.c | 2 +- examples/priority.c | 2 +- examples/queue.c | 4 ++-- examples/random.c | 4 ++-- examples/replace.c | 2 +- examples/words.c | 10 +++++----- stc/carray.h | 8 ++++---- stc/cbitset.h | 6 +++--- stc/cdefs.h | 18 +++++++++--------- stc/clist.h | 18 +++++++++--------- stc/cmap.h | 44 ++++++++++++++++++++++---------------------- stc/coption.h | 6 +++--- stc/cpqueue.h | 4 ++-- stc/cqueue.h | 4 ++-- stc/cstack.h | 2 +- stc/cstr.h | 22 +++++++++++----------- stc/cvec.h | 16 ++++++++-------- 31 files changed, 184 insertions(+), 184 deletions(-) diff --git a/README.md b/README.md index a4289f21..be345390 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ All containers mentioned above, except cstr_t and cbitset_t are generic and type using_cvec(i, int); int main(void) { - cvec_i vec = cvec_ini; + cvec_i vec = cvec_INIT; cvec_i_push_back(&vec, 42); - cvec_i_destroy(&vec); + cvec_i_del(&vec); } ``` Motivation @@ -126,7 +126,7 @@ This is a problem because cstr_t key may exist in the map, and it would need to ``` cstr lookup = cstr("mykey"); int x = cmap_si_find(&map, lookup)->value; -cstr_destroy(&lookup); +cstr_del(&lookup); ``` To avoid this, use - *using_cmap_strkey(tag, valuetype)* @@ -136,10 +136,10 @@ To avoid this, use ``` using_cmap_strkey(si, int); ... -cmap_si map = cmap_ini; +cmap_si map = cmap_INIT; cmap_si_put(&map, "mykey", 12); // constructs a cstr_t key from the const char* internally. int x = cmap_si_find(&map, "mykey")->value; // no allocation of string key happens here. -cmap_si_destroy(&map); +cmap_si_del(&map); ``` An alternative is to use *char* * as key type, but then you must manage allcoated memory of the hash char* keys yourself. Note that this predefined customization is also available for **cvec** and **clist**. See *using_cvec_str()*, *using_clist_str()*. @@ -184,7 +184,7 @@ int main() { using_cvec(ix, int64_t); // ix is just an example type tag name. int main() { - cvec_ix bignums = cvec_ini; // use cvec_ix_init() if initializing after declaration. + cvec_ix bignums = cvec_INIT; // use cvec_ix_init() 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); @@ -193,7 +193,7 @@ int main() { uint64_t value; for (size_t i = 0; i < cvec_size(bignums); ++i) value = bignums.data[i]; - cvec_ix_destroy(&bignums); + cvec_ix_del(&bignums); } ``` **cvec** of *cstr_t*. @@ -203,7 +203,7 @@ int main() { using_cvec_str(); int main() { - cvec_str names = cvec_ini; + cvec_str names = cvec_INIT; cvec_str_emplace_back(&names, "Mary"); cvec_str_emplace_back(&names, "Joe"); cstr_assign(&names.data[1], "Jake"); // replace "Joe". @@ -213,7 +213,7 @@ int main() { printf("%s\n", names.data[1].str); // Access the string char* c_foreach (i, cvec_str, names) printf("get %s\n", i.get->str); - cvec_str_destroy(&names); + cvec_str_del(&names); } ``` **cmap** of *int -> int*. @@ -223,12 +223,12 @@ int main() { using_cmap(ii, int, int); int main() { - cmap_ii nums = cmap_ini; + cmap_ii nums = cmap_INIT; cmap_ii_put(&nums, 8, 64); // similar to insert_or_assign() cmap_ii_emplace(&nums, 11, 121); printf("%d\n", cmap_ii_find(nums, 8)->value); - cmap_ii_destroy(&nums); + cmap_ii_del(&nums); } ``` **cset** of *cstr*. @@ -238,7 +238,7 @@ int main() { using_cset_str(); // cstr set. See the discussion above. int main() { - cset_str words = cset_ini; + cset_str words = cset_INIT; cset_str_insert(&words, "Hello"); cset_str_insert(&words, "Cruel"); cset_str_insert(&words, "World"); @@ -247,7 +247,7 @@ int main() { // iterate the set: c_foreach (i, cset_str, words) printf("%s\n", i.get->key.str); - cset_str_destroy(&words); + cset_str_del(&words); } ``` **cmap** of *cstr -> cstr*. Both cstr keys and values are created internally via *cstr()* from const char* inputs. @@ -257,7 +257,7 @@ int main() { using_cmap_str(); int main() { - cmap_str table = cmap_ini; + cmap_str table = cmap_INIT; cmap_str_put(&table, "Make", "my"); cmap_str_put(&table, "Rainy", "day"); cmap_str_put(&table, "Sunny", "afternoon"); @@ -267,7 +267,7 @@ int main() { printf("size = %zu\n", cmap_size(table)); c_foreach (i, cmap_str, table) printf("%s: %s\n", i.get->key.str, i.get->value.str); - cmap_str_destroy(&table); // frees key and value cstrs, and hash table. + cmap_str_del(&table); // frees key and value cstrs, and hash table. } ``` **clist** of *int64_t*. Similar to c++ *std::forward_list*, but can do both *push_front()* and *push_back()* as well as *pop_front()*. @@ -279,7 +279,7 @@ int main() { using_clist(fx, double); int main() { - clist_fx list = clist_ini; + clist_fx list = clist_INIT; crand_eng64_t eng = crand_eng64_init(time(NULL)); crand_uniform_f64_t dist = crand_uniform_f64_init(100.0, 1000.0); int k; @@ -306,7 +306,7 @@ int main() { printf("%f ", i.get->value); puts(""); - clist_fx_destroy(&list); + clist_fx_del(&list); } ``` **carray**. 1d, 2d and 3d arrays, allocated from heap in one memory block. *carray3* may have sub-array "views" of *carray2* and *carray1* etc., as shown in the following example: @@ -327,8 +327,8 @@ int main() printf("%f\n", *carray2f_at(a2, 4, 3)); // a2[4][3] (3.14f) printf("%f\n", *carray3f_at(a3, 5, 4, 3)); // a3[5][4][3] (3.14f) // ... - carray2f_destroy(&a1); // does nothing, since it is a sub-array. - carray2f_destroy(&a2); // same. - carray3f_destroy(&a3); // free array, and invalidates a1, a2. + carray2f_del(&a1); // does nothing, since it is a sub-array. + carray2f_del(&a2); // same. + carray3f_del(&a3); // free array, and invalidates a1, a2. } ``` diff --git a/examples/README.md b/examples/README.md index 95880385..74ac4384 100644 --- a/examples/README.md +++ b/examples/README.md @@ -39,9 +39,9 @@ typedef struct Viking { } Viking; -void viking_destroy(Viking* vk) { - cstr_destroy(&vk->name); - cstr_destroy(&vk->country); +void viking_del(Viking* vk) { + cstr_del(&vk->name); + cstr_del(&vk->country); } static inline VikingVw viking_toVw(Viking* vk) { @@ -53,14 +53,14 @@ static inline Viking viking_fromVw(VikingVw vw) { // note: parameter is by value ``` With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type: ``` -using_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, - viking_destroy, VikingVw, viking_toVw, viking_fromVw); +using_cmap(vk, Viking, int, c_default_del, vikingvw_equals, vikingvw_hash, + viking_del, VikingVw, viking_toVw, viking_fromVw); ``` -cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. cmap_vk_destroy() will free all memory allocated for Viking keys and the hash table values. +cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_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: ``` int main() { - cmap_vk vikings = cmap_ini; + cmap_vk vikings = cmap_INIT; c_push_items(&vikings, cmap_vk, { { {"Einar", "Norway"}, 20 }, { {"Olaf", "Denmark"}, 24 }, @@ -74,6 +74,6 @@ int main() { c_foreach (k, cmap_vk, vikings) { printf("%s of %s has %d hp\n", k.get->key.name.str, k.get->key.country.str, k.get->value); } - cmap_vk_destroy(&vikings); + cmap_vk_del(&vikings); } ``` diff --git a/examples/advanced.c b/examples/advanced.c index 200ab5a3..7cf55d2c 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -22,9 +22,9 @@ typedef struct Viking { } Viking; -void viking_destroy(Viking* vk) { - cstr_destroy(&vk->name); - cstr_destroy(&vk->country); +void viking_del(Viking* vk) { + cstr_del(&vk->name); + cstr_del(&vk->country); } // Viking view struct ----------------------- @@ -51,17 +51,17 @@ Viking viking_fromVw(VikingVw vw) { } // Using the full using_cmap() macro to define [Viking -> int] hash map type: -using_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, - viking_destroy, VikingVw, viking_toVw, viking_fromVw); +using_cmap(vk, Viking, int, c_default_del, vikingvw_equals, vikingvw_hash, + viking_del, VikingVw, viking_toVw, viking_fromVw); // cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. -// cmap_vk_destroy() will free all memory allocated for Viking keys and the hash table values. +// cmap_vk_del() will free all memory allocated for Viking keys and the hash table values. // Main ---------------------------- int main() { - cmap_vk vikings = cmap_ini; + cmap_vk vikings = cmap_INIT; c_push_items(&vikings, cmap_vk, { {{"Einar", "Norway"}, 20}, {{"Olaf", "Denmark"}, 24}, @@ -76,6 +76,6 @@ int main() c_foreach (k, cmap_vk, vikings) { printf("%s of %s has %d hp\n", k.get->first.name.str, k.get->first.country.str, k.get->second); } - cmap_vk_destroy(&vikings); + cmap_vk_del(&vikings); } diff --git a/examples/benchmark.c b/examples/benchmark.c index a02e8be8..e9719dbf 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -22,7 +22,7 @@ static inline uint32_t fibonacci_hash(const void* data, size_t len) { } // cmap and khash template expansion -using_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash); // c_default_hash16); +using_cmap(ii, int64_t, int64_t, c_default_del, c_default_equals, fibonacci_hash); // c_default_hash16); KHASH_MAP_INIT_INT64(ii, int64_t) @@ -34,7 +34,7 @@ crand_rng64_t rng; #define RAND(N) (crand_i64(&rng) & ((1 << N) - 1)) -#define CMAP_SETUP(X, Key, Value) cmap_##X map = cmap_ini \ +#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) @@ -45,7 +45,7 @@ crand_rng64_t rng; #define CMAP_SIZE(X) cmap_size(map) #define CMAP_BUCKETS(X) cmap_##X##_bucket_count(map) #define CMAP_CLEAR(X) cmap_##X##_clear(&map) -#define CMAP_DTOR(X) cmap_##X##_destroy(&map) +#define CMAP_DTOR(X) cmap_##X##_del(&map) #define KMAP_SETUP(X, Key, Value) khash_t(ii)* map = kh_init(ii); khiter_t ki; int ret #define KMAP_PUT(X, key, val) (*(ki = kh_put(ii, map, key, &ret), map->vals[ki] = val, &map->vals[ki])) diff --git a/examples/birthday.c b/examples/birthday.c index 7bee3658..59a47bdb 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_ini; + cmap_ic m = cmap_INIT; cmap_ic_reserve(&m, N); clock_t now = clock(); for (size_t i = 0; i < N; ++i) { diff --git a/examples/bits.c b/examples/bits.c index 28d1cfff..08b45669 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -9,7 +9,7 @@ int main() { cbitset_resize(&set, 43, false); cstr_t str = cbitset_to_str(set); printf(" str: %s\n", str.str); - cstr_destroy(&str); + cstr_del(&str); printf("%4zu: ", set.size); for (int i=0; i #include -void check_destroy(float* v) {printf("destroy %g\n", *v);} +void check_del(float* v) {printf("destroy %g\n", *v);} -using_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy. -using_clist(y, carray2f, carray2f_destroy, c_no_compare); -using_cmap(g, int, clist_y, clist_y_destroy); -using_cmap_strkey(s, cmap_g, cmap_g_destroy); +using_carray(f, float, check_del); // normally omit the last argument - float type need no destroy. +using_clist(y, carray2f, carray2f_del, c_no_compare); +using_cmap(g, int, clist_y, clist_y_del); +using_cmap_strkey(s, cmap_g, cmap_g_del); int main() { int xdim = 4, ydim = 6; int x = 1, y = 5, tableKey = 42; const char* strKey = "first"; - cmap_s myMap = cmap_ini; + cmap_s myMap = cmap_INIT; { // Construct. carray2f table = carray2f_make(ydim, xdim, 0.f); printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table)); - clist_y tableList = clist_ini; + clist_y tableList = clist_INIT; // Put in some data. - cmap_g listMap = cmap_ini; + cmap_g listMap = cmap_INIT; *carray2f_at(&table, y, x) = 3.1415927f; // table[y][x] clist_y_push_back(&tableList, table); @@ -33,5 +33,5 @@ int main() { printf("value (%d, %d) is: %f\n", y, x, *carray2f_at(&table, y, x)); } - c_dtor(cmap_s, &myMap); // free up everything! + c_del_(cmap_s, &myMap); // free up everything! } \ No newline at end of file diff --git a/examples/demos.c b/examples/demos.c index 6f5c0207..85d96e7e 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -30,7 +30,7 @@ void stringdemo1() cstr_append(&cs, " eight"); printf("append: %s\n", cs.str); - cstr_destroy(&cs); + cstr_del(&cs); } @@ -39,7 +39,7 @@ using_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1() { printf("\nVECTORDEMO1\n"); - cvec_ix bignums = cvec_ini; // = (cvec_ix) cvec_ini; 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) cvec_ix_push_back(&bignums, i * i * i); @@ -50,7 +50,7 @@ void vectordemo1() for (size_t i = 0; i < cvec_size(bignums); ++i) { if (i >= 90) printf("%zu: %zu\n", i, bignums.data[i]); } - cvec_ix_destroy(&bignums); + cvec_ix_del(&bignums); } @@ -60,7 +60,7 @@ using_cvec_str(); void vectordemo2() { printf("\nVECTORDEMO2\n"); - cvec_str names = cvec_ini; + cvec_str names = cvec_INIT; cvec_str_emplace_back(&names, "Mary"); cvec_str_emplace_back(&names, "Joe"); cvec_str_emplace_back(&names, "Chris"); @@ -70,7 +70,7 @@ void vectordemo2() cvec_str_sort(&names); // Sort the array c_foreach (i, cvec_str, names) printf("sorted: %s\n", i.get->str); - cvec_str_destroy(&names); + cvec_str_del(&names); } using_clist(ix, int); @@ -78,7 +78,7 @@ using_clist(ix, int); void listdemo1() { printf("\nLISTDEMO1\n"); - clist_ix nums = clist_ini, nums2 = clist_ini; + clist_ix nums = clist_INIT, nums2 = clist_INIT; for (int i = 0; i < 10; ++i) clist_ix_push_back(&nums, i); for (int i = 100; i < 110; ++i) @@ -97,7 +97,7 @@ void listdemo1() clist_ix_push_front(&nums, -99); c_foreach (i, clist_ix, nums) printf("sorted: %d\n", *i.get); - clist_ix_destroy(&nums); + clist_ix_del(&nums); } using_cset(i, int); @@ -105,13 +105,13 @@ using_cset(i, int); void setdemo1() { printf("\nSETDEMO1\n"); - cset_i nums = cset_ini; + cset_i nums = cset_INIT; cset_i_insert(&nums, 8); cset_i_insert(&nums, 11); c_foreach (i, cset_i, nums) printf("set: %d\n", *i.get); - cset_i_destroy(&nums); + cset_i_del(&nums); } @@ -120,11 +120,11 @@ using_cmap(ii, int, int); void mapdemo1() { printf("\nMAPDEMO1\n"); - cmap_ii nums = cmap_ini; + cmap_ii nums = cmap_INIT; cmap_ii_put(&nums, 8, 64); cmap_ii_put(&nums, 11, 121); printf("get 8: %d\n", *cmap_ii_at(&nums, 8)); - cmap_ii_destroy(&nums); + cmap_ii_del(&nums); } @@ -133,7 +133,7 @@ using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expans void mapdemo2() { printf("\nMAPDEMO2\n"); - cmap_si nums = cmap_ini; + 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 @@ -146,7 +146,7 @@ void mapdemo2() c_foreach (i, cmap_si, nums) printf("short: %s: %d\n", i.get->first.str, i.get->second); - cmap_si_destroy(&nums); + cmap_si_del(&nums); } @@ -155,7 +155,7 @@ using_cmap_str(); void mapdemo3() { printf("\nMAPDEMO3\n"); - cmap_str table = cmap_ini; + cmap_str table = cmap_INIT; cmap_str_put(&table, "Map", "test"); cmap_str_put(&table, "Make", "my"); cmap_str_put(&table, "Sunny", "day"); @@ -168,7 +168,7 @@ void mapdemo3() printf("size %zu\n", cmap_size(table)); c_foreach (i, cmap_str, table) printf("entry: %s: %s\n", i.get->first.str, i.get->second.str); - cmap_str_destroy(&table); // frees key and value cstrs, and hash table. + cmap_str_del(&table); // frees key and value cstrs, and hash table. } @@ -193,8 +193,8 @@ void arraydemo1() *i.get = 1.0f; printf("%f\n", *carray3f_at(&a3, 29, 19, 9)); - carray2f_destroy(&a2); // does nothing, since it is a sub-array. - carray3f_destroy(&a3); // also invalidates a2. + carray2f_del(&a2); // does nothing, since it is a sub-array. + carray3f_del(&a3); // also invalidates a2. } diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 033c0ebd..e5dad57a 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -14,7 +14,7 @@ static int compare(cmap_i_entry_t *a, cmap_i_entry_t *b) { return c_default_compare(&a->first, &b->first); } // Vector: typetag 'e' for (map) entry -using_cvec(e, cmap_i_entry_t, c_default_destroy, compare); +using_cvec(e, cmap_i_entry_t, c_default_del, compare); int main() { @@ -29,20 +29,20 @@ int main() crand_normal_f64_t dist = crand_normal_f64_init(Mean, StdDev); // Create histogram map - cmap_i mhist = cmap_ini; + cmap_i mhist = cmap_INIT; for (size_t i = 0; i < N; ++i) { int index = (int) round( crand_normal_f64(&rng, &dist) ); cmap_i_emplace(&mhist, index, 0).first->second += 1; } // Transfer map to vec and sort it by map keys. - cvec_e vhist = cvec_ini; + cvec_e vhist = cvec_INIT; c_foreach (i, cmap_i, mhist) cvec_e_push_back(&vhist, *i.get); cvec_e_sort(&vhist); // Print the gaussian bar chart - cstr_t bar = cstr_ini; + cstr_t bar = cstr_INIT; c_foreach (i, cvec_e, vhist) { size_t n = (size_t) (i.get->second * Mag / N); if (n > 0) { @@ -52,7 +52,7 @@ int main() } } // Cleanup - cstr_destroy(&bar); - cmap_i_destroy(&mhist); - cvec_e_destroy(&vhist); + cstr_del(&bar); + cmap_i_del(&mhist); + cvec_e_del(&vhist); } diff --git a/examples/heap.c b/examples/heap.c index 89f700d2..44e9b05e 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -41,5 +41,5 @@ int main() printf("%.0f ", *cpqueue_f_top(&pq)), cpqueue_f_pop(&pq); puts(""); - cpqueue_f_destroy(&pq); + cpqueue_f_del(&pq); } diff --git a/examples/inits.c b/examples/inits.c index c64ca574..14fe8a64 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -5,7 +5,7 @@ #include #include -using_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t +using_cmap(id, int, cstr_t, cstr_del); // Map of int -> cstr_t using_cmap_strkey(cnt, int); typedef struct {int x, y;} ipair_t; @@ -13,8 +13,8 @@ inline static int ipair_compare(const ipair_t* a, const ipair_t* b) { int c = c_default_compare(&a->x, &b->x); return c != 0 ? c : c_default_compare(&a->y, &b->y); } -using_cvec(ip, ipair_t, c_default_destroy, ipair_compare); -using_clist(ip, ipair_t, c_default_destroy, ipair_compare); +using_cvec(ip, ipair_t, c_default_del, ipair_compare); +using_clist(ip, ipair_t, c_default_del, ipair_compare); using_cvec(f, float); using_cpqueue(f, cvec_f, >); @@ -24,7 +24,7 @@ int main(void) { // CVEC FLOAT / PRIORITY QUEUE - cvec_f floats = cvec_ini; + 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) printf("%.1f ", *i.get); @@ -41,12 +41,12 @@ int main(void) { cpqueue_f_pop(&floats); } puts("\n"); - cpqueue_f_destroy(&floats); + cpqueue_f_del(&floats); // CMAP ID int year = 2020; - cmap_id idnames = cmap_ini; + cmap_id idnames = cmap_INIT; c_push_items(&idnames, cmap_id, { {100, cstr("Hello")}, {110, cstr("World")}, @@ -56,11 +56,11 @@ int main(void) { c_foreach (i, cmap_id, idnames) printf("%d: %s\n", i.get->first, i.get->second.str); puts(""); - cmap_id_destroy(&idnames); + cmap_id_del(&idnames); // CMAP CNT - cmap_cnt countries = cmap_ini; + cmap_cnt countries = cmap_INIT; c_push_items(&countries, cmap_cnt, { {"Norway", 100}, {"Denmark", 50}, @@ -79,11 +79,11 @@ int main(void) { c_foreach (i, cmap_cnt, countries) printf("%s: %d\n", i.get->first.str, i.get->second); puts(""); - cmap_cnt_destroy(&countries); + cmap_cnt_del(&countries); // CVEC PAIR - cvec_ip pairs1 = cvec_ini; + cvec_ip pairs1 = cvec_INIT; c_push_items(&pairs1, cvec_ip, { {5, 6}, {3, 4}, @@ -95,11 +95,11 @@ int main(void) { c_foreach (i, cvec_ip, pairs1) printf("(%d %d) ", i.get->x, i.get->y); puts(""); - cvec_ip_destroy(&pairs1); + cvec_ip_del(&pairs1); // CLIST PAIR - clist_ip pairs2 = clist_ini; + clist_ip pairs2 = clist_INIT; c_push_items(&pairs2, clist_ip, { {5, 6}, {3, 4}, @@ -111,5 +111,5 @@ int main(void) { c_foreach (i, clist_ip, pairs2) printf("(%d %d) ", i.get->x, i.get->y); puts(""); - clist_ip_destroy(&pairs2); + clist_ip_del(&pairs2); } \ No newline at end of file diff --git a/examples/list.c b/examples/list.c index abc4d5b7..c2bfec55 100644 --- a/examples/list.c +++ b/examples/list.c @@ -8,7 +8,7 @@ int main() { int k; const int n = 2000000; - clist_fx list = clist_ini; + 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; @@ -50,5 +50,5 @@ int main() { c_foreach (i, clist_fx, it, clist_fx_end(&list)) printf(" %g", *i.get); puts(""); - clist_fx_destroy(&list); + clist_fx_del(&list); } \ No newline at end of file diff --git a/examples/mapmap.c b/examples/mapmap.c index 57bcf384..38e88712 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -4,11 +4,11 @@ #include using_cmap_str(); -using_cmap_strkey(cfg, cmap_str, cmap_str_destroy); +using_cmap_strkey(cfg, cmap_str, cmap_str_del); int main(void) { - cmap_cfg config = cmap_ini; - cmap_str init = cmap_ini; + 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"); @@ -22,5 +22,5 @@ int main(void) { c_foreach (j, cmap_str, i.get->second) printf("%s: %s - %s (%u)\n", i.get->first.str, j.get->first.str, j.get->second.str, i.get->second.bucket_count); - cmap_cfg_destroy(&config); + cmap_cfg_del(&config); } \ No newline at end of file diff --git a/examples/phonebook.c b/examples/phonebook.c index 25d6ddb0..90d2fe22 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_ini; + cmap_str phone_book = cmap_INIT; c_push_items(&phone_book, cmap_str, { {"Lilia Friedman", "(892) 670-4739"}, {"Tariq Beltran", "(489) 600-7575"}, @@ -67,6 +67,6 @@ int main(int argc, char **argv) printf("\nPhone book after update phone of Zak Byers:\n"); print_phone_book(phone_book); - cmap_str_destroy(&phone_book); + cmap_str_del(&phone_book); puts("done"); } \ No newline at end of file diff --git a/examples/prime.c b/examples/prime.c index d5b0b186..e49d2f20 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -33,5 +33,5 @@ int main(void) for (uint32_t i = 2; i <= 1000; ++i) if (cbitset_test(primes, i)) printf("%u ", i); puts(""); - cbitset_destroy(&primes); + cbitset_del(&primes); } \ No newline at end of file diff --git a/examples/priority.c b/examples/priority.c index 12e4be25..722d3164 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -31,5 +31,5 @@ int main() { printf("%zd ", *cpqueue_i_top(&heap)); cpqueue_i_pop(&heap); } - cpqueue_i_destroy(&heap); + cpqueue_i_del(&heap); } diff --git a/examples/queue.c b/examples/queue.c index e1eaf5d4..fc1c2704 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -16,7 +16,7 @@ int main() { // Push ten million random numbers onto the queue. for (int i=0; i0; --i) { @@ -27,5 +27,5 @@ int main() { --n, cqueue_i_pop(&queue); } printf("%d, %zu\n", n, cqueue_i_size(queue)); - cqueue_i_destroy(&queue); + cqueue_i_del(&queue); } diff --git a/examples/random.c b/examples/random.c index b81f1826..df10acdc 100644 --- a/examples/random.c +++ b/examples/random.c @@ -58,10 +58,10 @@ int main() if (n >= 0 && n < R) ++hist[n]; } - cstr_t bar = cstr_ini; + cstr_t bar = cstr_INIT; 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); } - cstr_destroy(&bar); + cstr_del(&bar); } \ No newline at end of file diff --git a/examples/replace.c b/examples/replace.c index c68a8940..c4929864 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -29,5 +29,5 @@ int main () cstr_replace(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5) printf("(5) %s\n", s.str); - c_dtor(cstr, &s, &m); // destroy + c_del_(cstr, &s, &m); // destroy } diff --git a/examples/words.c b/examples/words.c index e22a2a9b..c5b513bf 100644 --- a/examples/words.c +++ b/examples/words.c @@ -11,7 +11,7 @@ using_cmap_strkey(si, int); int main1() { - clist_str lwords = clist_ini; + 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() printf("%s\n", w.get->str); puts(""); - cvec_str words = cvec_ini; + 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_ini; + cmap_si word_map = cmap_INIT; c_foreach (w, cvec_str, words) cmap_si_emplace(&word_map, w.get->str, 0).first->second += 1; @@ -37,8 +37,8 @@ int main1() pair.get->first.str); } - cmap_si_destroy(&word_map); - cvec_str_destroy(&words); + cmap_si_del(&word_map); + cvec_str_del(&words); return 0; } diff --git a/stc/carray.h b/stc/carray.h index a2f0a6ea..5a525d66 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -40,8 +40,8 @@ int main() printf("%f\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f) printf("%f\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array. - carray2f_destroy(&a2); // does nothing, since it is a sub-array. - carray3f_destroy(&a3); // also invalidates a2. + carray2f_del(&a2); // does nothing, since it is a sub-array. + carray3f_del(&a3); // also invalidates a2. } */ @@ -83,7 +83,7 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) { carray##D##X##_next(carray##D##X##_iter_t* it) {++it->get;} \ \ STC_INLINE void \ - carray##D##X##_destroy(carray##D##X* self) { \ + carray##D##X##_del(carray##D##X* self) { \ if (self->_xdim & _carray_OWN) { \ c_foreach_3 (i, carray##D##X, *self) \ valueDestroy(i.get); \ @@ -93,7 +93,7 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) { #define using_carray(...) c_MACRO_OVERLOAD(using_carray, __VA_ARGS__) #define using_carray_2(X, Value) \ - using_carray_3(X, Value, c_default_destroy) + using_carray_3(X, Value, c_default_del) #define using_carray_3(X, Value, valueDestroy) \ diff --git a/stc/cbitset.h b/stc/cbitset.h index b20aedd2..7801423f 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -37,7 +37,7 @@ int main() { cbitset_resize(&bset, 102, true); cbitset_set_value(&bset, 99, false); printf("%4zu: ", bset.size); for (int i=0; i_arr); } diff --git a/stc/cdefs.h b/stc/cdefs.h index f73eec06..c10d3899 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -78,29 +78,29 @@ #define c_default_less(x, y) (*(x) < *(y)) #define c_less_compare(less, x, y) (less(x, y) ? -1 : less(y, x)) #define c_default_compare(x, y) c_less_compare(c_default_less, x, y) -#define c_default_destroy(ptr) ((void) (ptr)) +#define c_default_del(ptr) ((void) (ptr)) #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__) - #define c_foreach_3(it, ctype, cnt) \ for (ctype##_iter_t it = ctype##_begin(&cnt), it##_end_ = ctype##_end(&cnt); it.get != it##_end_.get; ctype##_next(&it)) #define c_foreach_4(it, ctype, start, finish) \ for (ctype##_iter_t it = start, it##_end_ = finish; it.get != it##_end_.get; ctype##_next(&it)) +#define c_for_range(...) c_MACRO_OVERLOAD(c_for_range, __VA_ARGS__) +#define c_for_range_3(type, i, stop) for (type i=0, i##_end_=stop; i < i##_end_; ++i) +#define c_for_range_4(type, i, start, stop) for (type i=start, i##_end_=stop; i < i##_end_; ++i) +#define c_for_range_5(type, i, start, stop, step) \ + for (type i=start, i##_inc_=step, i##_end_=stop - (i##_inc_ > 0); (i <= i##_end_) == (0 < i##_inc_); i += i##_inc_) + #define c_push_items(self, ctype, ...) do { \ const ctype##_input_t __arr[] = __VA_ARGS__; \ ctype##_push_n(self, __arr, sizeof(__arr)/sizeof(__arr[0])); \ } while (0) -#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_dtor(ctype, ...) do { \ +#define c_del_(ctype, ...) do { \ struct ctype* __arr[] = {__VA_ARGS__}; \ for (size_t i=0; ivalue); - clist_ix_destroy(&list); + clist_ix_del(&list); } */ #define using_clist(...) c_MACRO_OVERLOAD(using_clist, __VA_ARGS__) #define using_clist_2(X, Value) \ - using_clist_3(X, Value, c_default_destroy) + using_clist_3(X, Value, c_default_del) #define using_clist_3(X, Value, valueDestroy) \ using_clist_4(X, Value, valueDestroy, c_default_compare) #define using_clist_4(X, Value, valueDestroy, valueCompare) \ using_clist_7(X, Value, valueDestroy, Value, \ valueCompare, c_default_to_raw, c_default_from_raw) -#define using_clist_str() using_clist_7(str, cstr_t, cstr_destroy, const char*, \ +#define using_clist_str() using_clist_7(str, cstr_t, cstr_del, const char*, \ cstr_compare_raw, cstr_to_raw, cstr) #define using_clist_types(X, Value) \ @@ -85,7 +85,7 @@ int _state; \ } clist_##X##_iter_t -#define clist_ini {NULL} +#define clist_INIT {NULL} #define clist_empty(list) ((list).last == NULL) #define c_emplace_after(self, ctype, pos, ...) do { \ @@ -108,7 +108,7 @@ STC_API size_t _clist_size(const clist_void* self); typedef clist_##X##_rawvalue_t clist_##X##_input_t; \ \ STC_INLINE clist_##X \ - clist_##X##_init(void) {clist_##X x = clist_ini; return x;} \ + clist_##X##_init(void) {clist_##X x = clist_INIT; return x;} \ STC_INLINE bool \ clist_##X##_empty(clist_##X ls) {return clist_empty(ls);} \ STC_INLINE size_t \ @@ -117,9 +117,9 @@ STC_API size_t _clist_size(const clist_void* self); clist_##X##_value_from_raw(RawValue rawValue) {return valueFromRaw(rawValue);} \ \ STC_API void \ - clist_##X##_destroy(clist_##X* self); \ + clist_##X##_del(clist_##X* self); \ STC_INLINE void \ - clist_##X##_clear(clist_##X* self) {clist_##X##_destroy(self);} \ + clist_##X##_clear(clist_##X* self) {clist_##X##_del(self);} \ \ STC_API void \ clist_##X##_push_n(clist_##X *self, const clist_##X##_input_t in[], size_t size); \ @@ -214,7 +214,7 @@ STC_API size_t _clist_size(const clist_void* self); #define _c_implement_clist_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw) \ \ STC_API void \ - clist_##X##_destroy(clist_##X* self) { \ + clist_##X##_del(clist_##X* self) { \ while (self->last) _clist_##X##_erase_after(self, self->last); \ } \ \ diff --git a/stc/cmap.h b/stc/cmap.h index 1cd2f180..7dfbe58f 100644 --- a/stc/cmap.h +++ b/stc/cmap.h @@ -27,14 +27,14 @@ using_cset(sx, int); // Set of int using_cmap(mx, int, char); // Map of int -> char int main(void) { - cset_sx s = cset_ini; + cset_sx s = cset_INIT; cset_sx_insert(&s, 5); cset_sx_insert(&s, 8); c_foreach (i, cset_sx, s) printf("set %d\n", i.get->second); - cset_sx_destroy(&s); + cset_sx_del(&s); - cmap_mx m = cmap_ini; + cmap_mx m = cmap_INIT; cmap_mx_put(&m, 5, 'a'); cmap_mx_put(&m, 8, 'b'); cmap_mx_put(&m, 12, 'c'); @@ -44,7 +44,7 @@ int main(void) { cmap_mx_erase(&m, 8); c_foreach (i, cmap_mx, m) printf("map %d: %c\n", i.get->first, i.get->second); - cmap_mx_destroy(&m); + cmap_mx_del(&m); }*/ #ifndef CMAP__H__ #define CMAP__H__ @@ -53,10 +53,10 @@ int main(void) { #include #include "cdefs.h" -#define cmap_ini {NULL, NULL, 0, 0, 0.85f, 0.15f} +#define cmap_INIT {NULL, NULL, 0, 0, 0.85f, 0.15f} #define cmap_empty(m) ((m).size == 0) #define cmap_size(m) ((size_t) (m).size) -#define cset_ini cmap_ini +#define cset_INIT cmap_INIT #define cset_empty(s) cmap_empty(s) #define cset_size(s) cmap_size(s) @@ -80,14 +80,14 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; c_MACRO_OVERLOAD(using_cmap, __VA_ARGS__) #define using_cmap_3(X, Key, Mapped) \ - using_cmap_4(X, Key, Mapped, c_default_destroy) + using_cmap_4(X, Key, Mapped, c_default_del) #define using_cmap_4(X, Key, Mapped, valueDestroy) \ using_cmap_6(X, Key, Mapped, valueDestroy, c_default_equals, c_default_hash16) #define using_cmap_6(X, Key, Mapped, valueDestroy, keyEquals, keyHash) \ using_cmap_10(X, Key, Mapped, valueDestroy, keyEquals, keyHash, \ - c_default_destroy, Key, c_default_to_raw, c_default_from_raw) + c_default_del, Key, c_default_to_raw, c_default_from_raw) #define using_cmap_10(X, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \ keyDestroy, RawKey, keyToRaw, keyFromRaw) \ @@ -107,7 +107,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; using_cset_4(X, Key, c_default_equals, c_default_hash16) #define using_cset_4(X, Key, keyEquals, keyHash) \ - using_cset_5(X, Key, keyEquals, keyHash, c_default_destroy) + using_cset_5(X, Key, keyEquals, keyHash, c_default_del) #define using_cset_5(X, Key, keyEquals, keyHash, keyDestroy) \ using_cset_8(X, Key, keyEquals, keyHash, keyDestroy, \ @@ -123,14 +123,14 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; _c_declare_CHASH_strkey(str, cset, cstr_t, void) #define using_cmap_str() \ - _c_typedef_CHASH(str, cmap, cstr_t, cstr_t, cstr_destroy, cstr_equals_raw, cstr_hash_raw, \ - cstr_destroy, const char*, cstr_to_raw, cstr, const char*, cstr) + _c_typedef_CHASH(str, cmap, cstr_t, cstr_t, cstr_del, cstr_equals_raw, cstr_hash_raw, \ + cstr_del, const char*, cstr_to_raw, cstr, const char*, cstr) #define using_cmap_strkey(...) \ c_MACRO_OVERLOAD(using_cmap_strkey, __VA_ARGS__) #define using_cmap_strkey_2(X, Mapped) \ - _c_declare_CHASH_strkey(X, cmap, Mapped, c_default_destroy) + _c_declare_CHASH_strkey(X, cmap, Mapped, c_default_del) #define using_cmap_strkey_3(X, Mapped, ValueDestroy) \ _c_declare_CHASH_strkey(X, cmap, Mapped, ValueDestroy) @@ -143,16 +143,16 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; #define using_cmap_strval_4(X, Key, keyEquals, keyHash) \ using_cmap_strval_8(X, Key, keyEquals, keyHash, \ - c_default_destroy, Key, c_default_to_raw, c_default_from_raw) + c_default_del, Key, c_default_to_raw, c_default_from_raw) #define using_cmap_strval_8(X, Key, keyEquals, keyHash, keyDestroy, RawKey, keyToRaw, keyFromRaw) \ - _c_typedef_CHASH(X, cmap, Key, cstr_t, cstr_destroy, keyEquals, keyHash, \ + _c_typedef_CHASH(X, cmap, Key, cstr_t, cstr_del, keyEquals, keyHash, \ keyDestroy, RawKey, keyToRaw, keyFromRaw, const char*, cstr) #define _c_declare_CHASH_strkey(X, ctype, Mapped, valueDestroy) \ _c_typedef_CHASH(X, ctype, cstr_t, Mapped, valueDestroy, cstr_equals_raw, cstr_hash_raw, \ - cstr_destroy, const char*, cstr_to_raw, cstr, Mapped, c_default_from_raw) + cstr_del, const char*, cstr_to_raw, cstr, Mapped, c_default_from_raw) #define CSET_ONLY_cset(...) __VA_ARGS__ #define CSET_ONLY_cmap(...) @@ -175,7 +175,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; ctype##_##X##_value_t, ctype##_##X##_entry_t; \ \ STC_INLINE void \ - ctype##_##X##_entry_destroy(ctype##_##X##_value_t* e) { \ + ctype##_##X##_entry_del(ctype##_##X##_value_t* e) { \ keyDestroy(&KEY_REF_##ctype(e)); \ CMAP_ONLY_##ctype(valueDestroy(&e->second);) \ } \ @@ -203,7 +203,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } ctype##_##X##_iter_t; \ \ STC_INLINE ctype##_##X \ - ctype##_##X##_init(void) {ctype##_##X m = cmap_ini; return m;} \ + ctype##_##X##_init(void) {ctype##_##X m = cmap_INIT; return m;} \ STC_INLINE bool \ ctype##_##X##_empty(ctype##_##X m) {return m.size == 0;} \ STC_INLINE size_t \ @@ -225,7 +225,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; STC_API void \ ctype##_##X##_push_n(ctype##_##X* self, const ctype##_##X##_input_t in[], size_t size); \ STC_API void \ - ctype##_##X##_destroy(ctype##_##X* self); \ + ctype##_##X##_del(ctype##_##X* self); \ STC_API void \ ctype##_##X##_clear(ctype##_##X* self); \ STC_API ctype##_##X##_value_t* \ @@ -318,7 +318,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \ STC_API ctype##_##X \ ctype##_##X##_with_capacity(size_t cap) { \ - ctype##_##X h = ctype##_ini; \ + ctype##_##X h = ctype##_INIT; \ ctype##_##X##_reserve(&h, cap); \ return h; \ } \ @@ -332,10 +332,10 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; if (self->size == 0) return; \ ctype##_##X##_value_t* e = self->table, *end = e + self->bucket_count; \ uint8_t *hx = self->_hashx; \ - for (; e != end; ++e) if (*hx++) ctype##_##X##_entry_destroy(e); \ + for (; e != end; ++e) if (*hx++) ctype##_##X##_entry_del(e); \ } \ \ - STC_API void ctype##_##X##_destroy(ctype##_##X* self) { \ + STC_API void ctype##_##X##_del(ctype##_##X* self) { \ ctype##_##X##_wipe_(self); \ free(self->_hashx); \ free(self->table); \ @@ -423,7 +423,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; size_t i = chash_entry_index(*self, get), j = i, k, cap = self->bucket_count; \ ctype##_##X##_value_t* slot = self->table; \ uint8_t* hashx = self->_hashx; \ - ctype##_##X##_entry_destroy(&slot[i]); \ + ctype##_##X##_entry_del(&slot[i]); \ do { /* deletion from hash table without tombstone */ \ if (++j == cap) j = 0; /* ++j; j %= cap; is slow */ \ if (! hashx[j]) \ diff --git a/stc/coption.h b/stc/coption.h index 4b0712d6..fe961ad9 100644 --- a/stc/coption.h +++ b/stc/coption.h @@ -43,7 +43,7 @@ Example: const char* optstr = "xy:z::123"; printf("program -x -y ARG -z [ARG] -1 -2 -3 --foo --bar ARG --opt [ARG] [ARGUMENTS]\n"); int c; - coption_t opt = coption_ini; + coption_t opt = coption_INIT; while ((c = coption_get(&opt, argc, argv, optstr, longopts)) != -1) { switch (c) { case '?': printf("error: unknown option: %s\n", opt.faulty); break; @@ -83,7 +83,7 @@ typedef struct { int val; } coption_long_t; -static const coption_t coption_ini = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', '?', '\0'}}; +static const coption_t coption_INIT = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', '?', '\0'}}; static void _coption_permute(char *argv[], int j, int n) { /* move argv[j] over n elements to the left */ int k; @@ -93,7 +93,7 @@ static void _coption_permute(char *argv[], int j, int n) { /* move argv[j] over argv[j - k] = p; } -/* @param opt output; must be initialized to coption_ini on first call +/* @param opt output; must be initialized to coption_INIT on first call * @return ASCII val for a short option; longopt.val for a long option; * -1 if argv[] is fully processed; '?' for an unknown option or * an ambiguous long option; ':' if an option argument is missing diff --git a/stc/cpqueue.h b/stc/cpqueue.h index 03fe09d2..4241cc32 100644 --- a/stc/cpqueue.h +++ b/stc/cpqueue.h @@ -41,7 +41,7 @@ printf("%f ", *cpqueue_f_top(queue)); cpqueue_f_pop(&queue); } - cpqueue_f_destroy(&queue); + cpqueue_f_del(&queue); } */ @@ -63,7 +63,7 @@ STC_INLINE bool \ cpqueue_##X##_empty(cpqueue_##X pq) {return ctype##_empty(pq);} \ STC_INLINE void \ - cpqueue_##X##_destroy(cpqueue_##X* self) {ctype##_destroy(self);} \ + cpqueue_##X##_del(cpqueue_##X* self) {ctype##_del(self);} \ STC_API void \ cpqueue_##X##_build(cpqueue_##X* self); \ STC_API void \ diff --git a/stc/cqueue.h b/stc/cqueue.h index 4a13c335..27346de6 100644 --- a/stc/cqueue.h +++ b/stc/cqueue.h @@ -49,7 +49,7 @@ --n, cqueue_i_pop(&queue); } printf("%d\n", n); - cqueue_i_destroy(&queue); + cqueue_i_del(&queue); } */ @@ -67,7 +67,7 @@ STC_INLINE cqueue_##X \ cqueue_##X##_init() {return ctype##_init();} \ STC_INLINE void \ - cqueue_##X##_destroy(cqueue_##X* self) {ctype##_destroy(self);} \ + cqueue_##X##_del(cqueue_##X* self) {ctype##_del(self);} \ STC_INLINE size_t \ cqueue_##X##_size(cqueue_##X pq) {return ctype##_size(pq);} \ STC_INLINE bool \ diff --git a/stc/cstack.h b/stc/cstack.h index 0d914445..0351a545 100644 --- a/stc/cstack.h +++ b/stc/cstack.h @@ -56,7 +56,7 @@ STC_INLINE cstack_##X \ cstack_##X##_init() {return ctype##_init();} \ STC_INLINE void \ - cstack_##X##_destroy(cstack_##X* self) {ctype##_destroy(self);} \ + cstack_##X##_del(cstack_##X* self) {ctype##_del(self);} \ STC_INLINE size_t \ cstack_##X##_size(cstack_##X pq) {return ctype##_size(pq);} \ STC_INLINE bool \ diff --git a/stc/cstr.h b/stc/cstr.h index 351e1beb..bb64bf5c 100644 --- a/stc/cstr.h +++ b/stc/cstr.h @@ -35,11 +35,11 @@ typedef char cstr_value_t; static size_t _cstr_nullrep[] = {0, 0, 0}; -static cstr_t cstr_ini = {(char* ) &_cstr_nullrep[2]}; +static cstr_t cstr_INIT = {(char* ) &_cstr_nullrep[2]}; #define cstr_size(s) ((const size_t *) (s).str)[-2] #define cstr_capacity(s) ((const size_t *) (s).str)[-1] #define cstr_empty(s) (cstr_size(s) == 0) -#define cstr_npos ((size_t) (-1)) +#define cstr_NPOS ((size_t) (-1)) STC_API cstr_t cstr_n(const char* str, size_t len); @@ -68,23 +68,23 @@ c_strnstr(const char* s, const char* needle, size_t n); #define _cstr_cap(size) ((((size) + 24) >> 4) * 16 - 9) STC_INLINE cstr_t -cstr_init() {return cstr_ini;} +cstr_init() {return cstr_INIT;} STC_INLINE void -cstr_destroy(cstr_t* self) { +cstr_del(cstr_t* self) { if (cstr_capacity(*self)) free(_cstr_rep(self)); } STC_INLINE cstr_t cstr_with_capacity(size_t cap) { - cstr_t s = cstr_ini; + cstr_t s = cstr_INIT; cstr_reserve(&s, cap); return s; } STC_INLINE cstr_t cstr_with_size(size_t len, char fill) { - cstr_t s = cstr_ini; + cstr_t s = cstr_INIT; cstr_resize(&s, len, fill); return s; } @@ -132,7 +132,7 @@ cstr_take(cstr_t* self, cstr_t s) { STC_INLINE cstr_t cstr_move(cstr_t* self) { cstr_t tmp = *self; - *self = cstr_ini; + *self = cstr_INIT; return tmp; } @@ -180,12 +180,12 @@ cstr_compare(const cstr_t *s1, const cstr_t *s2) { STC_INLINE size_t cstr_find_n(const cstr_t* s, const char* needle, size_t pos, size_t n) { char* res = c_strnstr(s->str + pos, needle, n); - return res ? res - s->str : cstr_npos; + return res ? res - s->str : cstr_NPOS; } STC_INLINE size_t cstr_find(const cstr_t* s, const char* needle) { char* res = strstr(s->str, needle); - return res ? res - s->str : cstr_npos; + return res ? res - s->str : cstr_NPOS; } /* cvec/cmap API functions: */ @@ -229,7 +229,7 @@ cstr_resize(cstr_t* self, size_t len, char fill) { STC_API cstr_t cstr_n(const char* str, size_t len) { - if (len == 0) return cstr_ini; + if (len == 0) return cstr_INIT; size_t *rep = (size_t *) malloc(_cstr_mem(len)); cstr_t s = {(char *) memcpy(rep + 2, str, len)}; s.str[rep[0] = len] = '\0'; @@ -246,7 +246,7 @@ cstr_from(const char* fmt, ...) { # pragma warning(push) # pragma warning(disable: 4996) #endif - cstr_t tmp = cstr_ini; + cstr_t tmp = cstr_INIT; va_list args, args2; va_start(args, fmt); va_copy(args2, args); diff --git a/stc/cvec.h b/stc/cvec.h index 6f292b33..f3c203ca 100644 --- a/stc/cvec.h +++ b/stc/cvec.h @@ -27,20 +27,20 @@ #include #include "cdefs.h" -#define cvec_ini {NULL} +#define cvec_INIT {NULL} #define cvec_size(v) _cvec_safe_size((v).data) #define cvec_capacity(v) _cvec_safe_capacity((v).data) #define cvec_empty(v) (cvec_size(v) == 0) #define using_cvec(...) c_MACRO_OVERLOAD(using_cvec, __VA_ARGS__) #define using_cvec_2(X, Value) \ - using_cvec_3(X, Value, c_default_destroy) + using_cvec_3(X, Value, c_default_del) #define using_cvec_3(X, Value, valueDestroy) \ using_cvec_4(X, Value, valueDestroy, c_default_compare) #define using_cvec_4(X, Value, valueDestroy, valueCompare) \ using_cvec_7(X, Value, valueDestroy, valueCompare, Value, c_default_to_raw, c_default_from_raw) #define using_cvec_str() \ - using_cvec_7(str, cstr_t, cstr_destroy, cstr_compare_raw, const char*, cstr_to_raw, cstr) + using_cvec_7(str, cstr_t, cstr_del, cstr_compare_raw, const char*, cstr_to_raw, cstr) #define using_cvec_7(X, Value, valueDestroy, valueCompareRaw, RawValue, valueToRaw, valueFromRaw) \ @@ -55,7 +55,7 @@ } cvec_##X; \ \ STC_INLINE cvec_##X \ - cvec_##X##_init(void) {cvec_##X v = cvec_ini; return v;} \ + cvec_##X##_init(void) {cvec_##X v = cvec_INIT; return v;} \ STC_INLINE bool \ cvec_##X##_empty(cvec_##X v) {return cvec_empty(v);} \ STC_INLINE size_t \ @@ -67,7 +67,7 @@ STC_INLINE void \ cvec_##X##_clear(cvec_##X* self); \ STC_API void \ - cvec_##X##_destroy(cvec_##X* self); \ + cvec_##X##_del(cvec_##X* self); \ STC_API void \ cvec_##X##_reserve(cvec_##X* self, size_t cap); \ STC_API void \ @@ -77,13 +77,13 @@ \ STC_INLINE cvec_##X \ cvec_##X##_with_size(size_t size, Value null_val) { \ - cvec_##X x = cvec_ini; \ + cvec_##X x = cvec_INIT; \ cvec_##X##_resize(&x, size, null_val); \ return x; \ } \ STC_INLINE cvec_##X \ cvec_##X##_with_capacity(size_t size) { \ - cvec_##X x = cvec_ini; \ + cvec_##X x = cvec_INIT; \ cvec_##X##_reserve(&x, size); \ return x; \ } \ @@ -208,7 +208,7 @@ } \ } \ STC_API void \ - cvec_##X##_destroy(cvec_##X* self) { \ + cvec_##X##_del(cvec_##X* self) { \ cvec_##X##_clear(self); \ if (self->data) free(_cvec_alloced(self->data)); \ } \ -- cgit v1.2.3