diff options
| author | Tyge Løvset <[email protected]> | 2020-09-15 22:43:41 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-15 22:43:41 +0200 |
| commit | f4435af2fc9e9187f7be0149c2eb916db27cb257 (patch) | |
| tree | 117429619290d165b7a3001f21f3c0e7f37a1045 /examples | |
| parent | f539099575e14aea9f2e043b9af33d05c47399ad (diff) | |
| download | STC-modified-f4435af2fc9e9187f7be0149c2eb916db27cb257.tar.gz STC-modified-f4435af2fc9e9187f7be0149c2eb916db27cb257.zip | |
New API Change.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/README.md | 8 | ||||
| -rw-r--r-- | examples/advanced.c | 8 | ||||
| -rw-r--r-- | examples/benchmark.c | 4 | ||||
| -rw-r--r-- | examples/birthday.c | 10 | ||||
| -rw-r--r-- | examples/complex.c | 8 | ||||
| -rw-r--r-- | examples/demos.c | 42 | ||||
| -rw-r--r-- | examples/ex_gaussian.c | 10 | ||||
| -rw-r--r-- | examples/geek1.c | 16 | ||||
| -rw-r--r-- | examples/geek2.c | 8 | ||||
| -rw-r--r-- | examples/geek3.c | 18 | ||||
| -rw-r--r-- | examples/geek4.c | 6 | ||||
| -rw-r--r-- | examples/geek5.c | 4 | ||||
| -rw-r--r-- | examples/geek6.c | 2 | ||||
| -rw-r--r-- | examples/geek7.c | 6 | ||||
| -rw-r--r-- | examples/heap.c | 4 | ||||
| -rw-r--r-- | examples/inits.c | 26 | ||||
| -rw-r--r-- | examples/list.c | 12 | ||||
| -rw-r--r-- | examples/mapmap.c | 8 | ||||
| -rw-r--r-- | examples/phonebook.c | 8 | ||||
| -rw-r--r-- | examples/priority.c | 4 | ||||
| -rw-r--r-- | examples/queue.c | 4 | ||||
| -rw-r--r-- | examples/replace.c | 2 | ||||
| -rw-r--r-- | examples/stack.c | 8 | ||||
| -rw-r--r-- | examples/words.c | 14 |
24 files changed, 120 insertions, 120 deletions
diff --git a/examples/README.md b/examples/README.md index 26eb4bb1..5c9c990a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -48,12 +48,12 @@ static inline VikingVw viking_toVw(Viking* vk) { VikingVw vw = {vk->name.str, vk->country.str}; return vw;
}
static inline Viking viking_fromVw(VikingVw vw) { // note: parameter is by value
- Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk;
+ Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
```
-With this in place, we use the full declare_cmap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full cdef_cmap() macro to define {Viking -> int} hash map type:
```
-declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, 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.
@@ -72,7 +72,7 @@ int main() { cmap_vk_emplace(&vikings, look, 0)->value += 5; // again
c_foreach (k, cmap_vk, vikings) {
- printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value);
+ 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);
}
diff --git a/examples/advanced.c b/examples/advanced.c index fe46f5da..ab2cec5f 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -47,11 +47,11 @@ VikingVw viking_toVw(Viking* vk) { VikingVw vw = {vk->name.str, vk->country.str}; return vw; } Viking viking_fromVw(VikingVw vw) { - Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk; + Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk; } -// Using the full declare_cmap() macro to define [Viking -> int] hash map type: -declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, +// Using the full cdef_cmap() macro to define [Viking -> int] hash map type: +cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash, viking_destroy, VikingVw, viking_toVw, viking_fromVw); // cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. @@ -74,7 +74,7 @@ int main() cmap_vk_emplace(&vikings, einar, 0).first->value += 5; // again c_foreach (k, cmap_vk, vikings) { - printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value); + 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); } diff --git a/examples/benchmark.c b/examples/benchmark.c index 3824e02f..04995de0 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
-declare_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
+cdef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
KHASH_MAP_INIT_INT64(ii, int64_t)
@@ -41,7 +41,7 @@ crand_rng64_t rng; #define CMAP_ERASE(tt, key) cmap_##tt##_erase(&map, key)
#define CMAP_FIND(tt, key) (cmap_##tt##_find(map, key) != NULL)
#define CMAP_FOR(tt, i) c_foreach (i, cmap_##tt, map)
-#define CMAP_ITEM(tt, i) i.item->value
+#define CMAP_ITEM(tt, i) i.get->value
#define CMAP_SIZE(tt) cmap_size(map)
#define CMAP_BUCKETS(tt) cmap_bucket_count(map)
#define CMAP_CLEAR(tt) cmap_##tt##_clear(&map)
diff --git a/examples/birthday.c b/examples/birthday.c index 59a8aee5..c6a9e541 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -7,7 +7,7 @@ #include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cmap(ic, uint64_t, uint8_t);
+cdef_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
@@ -29,8 +29,8 @@ void repeats(void) }
-declare_cmap(x, uint32_t, uint64_t);
-declare_cvec(x, uint64_t);
+cdef_cmap(x, uint32_t, uint64_t);
+cdef_cvec(x, uint64_t);
void distribution(void)
{
@@ -45,11 +45,11 @@ void distribution(void) float diff = (float) (clock() - now) / CLOCKS_PER_SEC;
uint64_t sum = 0;
- c_foreach (i, cmap_x, map) sum += i.item->value;
+ c_foreach (i, cmap_x, map) sum += i.get->value;
sum /= map.size;
c_foreach (i, cmap_x, map)
- printf("%u: %zu - %zu\n", i.item->key, i.item->value, sum);
+ printf("%u: %zu - %zu\n", i.get->key, i.get->value, sum);
printf("%.02f\n", diff);
}
diff --git a/examples/complex.c b/examples/complex.c index 151824e2..f129884a 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -5,10 +5,10 @@ void check_destroy(float* v) {printf("destroy %g\n", *v);}
-declare_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
-declare_clist(y, carray2f, carray2f_destroy, c_no_compare);
-declare_cmap(g, int, clist_y, clist_y_destroy);
-declare_cmap_strkey(s, cmap_g, cmap_g_destroy);
+cdef_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
+cdef_clist(y, carray2f, carray2f_destroy, c_no_compare);
+cdef_cmap(g, int, clist_y, clist_y_destroy);
+cdef_cmap_strkey(s, cmap_g, cmap_g_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c index 7b204aa1..b3ed91bb 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -8,7 +8,7 @@ void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- cstr_t cs = cstr_make("one-nine-three-seven-five");
+ cstr_t cs = cstr("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
@@ -34,7 +34,7 @@ void stringdemo1() }
-declare_cvec(ix, int64_t); // ix is just an example tag name.
+cdef_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
@@ -55,7 +55,7 @@ void vectordemo1() -declare_cvec_str();
+cdef_cvec_str();
void vectordemo2()
{
@@ -69,11 +69,11 @@ void vectordemo2() cvec_str_sort(&names); // Sort the array
c_foreach (i, cvec_str, names)
- printf("sorted: %s\n", i.item->str);
+ printf("sorted: %s\n", i.get->str);
cvec_str_destroy(&names);
}
-declare_clist(ix, int);
+cdef_clist(ix, int);
void listdemo1()
{
@@ -84,23 +84,23 @@ void listdemo1() for (int i = 100; i < 110; ++i)
clist_ix_push_back(&nums2, i);
c_foreach (i, clist_ix, nums)
- printf("value: %d\n", i.item->value);
+ printf("value: %d\n", i.get->value);
/* merge/append nums2 to nums */
clist_ix_splice_front(&nums, &nums2);
c_foreach (i, clist_ix, nums)
- printf("spliced: %d\n", i.item->value);
+ printf("spliced: %d\n", i.get->value);
- clist_ix_find(&nums, 100).item->value *= 10;
+ clist_ix_find(&nums, 100).get->value *= 10;
clist_ix_sort(&nums); // Sort the array
clist_ix_remove(&nums, 105);
clist_ix_pop_front(&nums);
clist_ix_push_front(&nums, -99);
c_foreach (i, clist_ix, nums)
- printf("sorted: %d\n", i.item->value);
+ printf("sorted: %d\n", i.get->value);
clist_ix_destroy(&nums);
}
-declare_cset(i, int);
+cdef_cset(i, int);
void setdemo1()
{
@@ -110,12 +110,12 @@ void setdemo1() cset_i_insert(&nums, 11);
c_foreach (i, cset_i, nums)
- printf("set: %d\n", i.item->value);
+ printf("set: %d\n", i.get->value);
cset_i_destroy(&nums);
}
-declare_cmap(ii, int, int);
+cdef_cmap(ii, int, int);
void mapdemo1()
{
@@ -128,7 +128,7 @@ void mapdemo1() }
-declare_cmap_strkey(si, int); // Shorthand macro for the general declare_cmap expansion.
+cdef_cmap_strkey(si, int); // Shorthand macro for the general cdef_cmap expansion.
void mapdemo2()
{
@@ -139,18 +139,18 @@ void mapdemo2() cmap_si_put(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(&nums); i.item != cmap_si_end(&nums).item; cmap_si_next(&i))
- printf("long: %s: %d\n", i.item->first.str, i.item->second);
+ for (cmap_si_iter_t i = cmap_si_begin(&nums); i.get != cmap_si_end(&nums).get; cmap_si_next(&i))
+ printf("long: %s: %d\n", i.get->first.str, i.get->second);
// or rather use the short form:
c_foreach (i, cmap_si, nums)
- printf("short: %s: %d\n", i.item->first.str, i.item->second);
+ printf("short: %s: %d\n", i.get->first.str, i.get->second);
cmap_si_destroy(&nums);
}
-declare_cmap_str();
+cdef_cmap_str();
void mapdemo3()
{
@@ -161,18 +161,18 @@ void mapdemo3() cmap_str_put(&table, "Sunny", "day");
cmap_str_value_t *e = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.item->first.str, i.item->second.str);
+ printf("entry: %s: %s\n", i.get->first.str, i.get->second.str);
printf("size %zu: remove: Make: %s\n", cmap_size(table), e->second.str);
cmap_str_erase(&table, "Make");
printf("size %zu\n", cmap_size(table));
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.item->first.str, i.item->second.str);
+ 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 (CVec).
}
-declare_carray(f, float);
+cdef_carray(f, float);
void arraydemo1()
{
@@ -190,7 +190,7 @@ void arraydemo1() printf("%f\n", *carray3f_at(&a3, 5, 4, 3)); // lookup a3[5][4][3] (=10.2f)
c_foreach (i, carray3f, a3)
- *i.item = 1.0f;
+ *i.get = 1.0f;
printf("%f\n", *carray3f_at(&a3, 29, 19, 9));
carray2f_destroy(&a2); // does nothing, since it is a sub-array.
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 66abb889..402fba32 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -7,14 +7,14 @@ #include <stc/cvec.h>
// Declare int -> int hashmap. Uses typetag 'i' for ints.
-declare_cmap(i, int, size_t);
+cdef_cmap(i, int, size_t);
// Declare int vector with map entries that can be sorted by map keys.
static int compare(cmap_i_entry_t *a, cmap_i_entry_t *b) {
return c_default_compare(&a->key, &b->key);
}
// Vector: typetag 'e' for (map) entry
-declare_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
+cdef_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
int main()
{
@@ -38,17 +38,17 @@ int main() // Transfer map to vec and sort it by map keys.
cvec_e vhist = cvec_ini;
c_foreach (i, cmap_i, mhist)
- cvec_e_push_back(&vhist, *i.item);
+ cvec_e_push_back(&vhist, *i.get);
cvec_e_sort(&vhist);
// Print the gaussian bar chart
cstr_t bar = cstr_ini;
c_foreach (i, cvec_e, vhist) {
- size_t n = (size_t) (i.item->value * Mag / N);
+ size_t n = (size_t) (i.get->value * Mag / N);
if (n > 0) {
// bar string: take ownership in new str after freeing current.
cstr_take(&bar, cstr_with_size(n, '*'));
- printf("%4d %s\n", i.item->key, bar.str);
+ printf("%4d %s\n", i.get->key, bar.str);
}
}
// Cleanup
diff --git a/examples/geek1.c b/examples/geek1.c index 983539b8..50e23032 100644 --- a/examples/geek1.c +++ b/examples/geek1.c @@ -12,7 +12,7 @@ int a[] = { 1, 2, 2, 3, 2, 4, 10 }; #include <stdio.h>
#include <stc/cmap.h>
-declare_cmap(ii, int, int);
+cdef_cmap(ii, int, int);
// Function to maximize the number of pairs
int findMaximumPairs(int a[], int n, int k)
@@ -30,13 +30,13 @@ int findMaximumPairs(int a[], int n, int k) c_foreach (it, cmap_ii, hash) {
// If the number is 0
- if (it.item->key == 0) {
+ if (it.get->key == 0) {
// We take half since same number
- count += it.item->value / 2;
- cmap_ii_put(&hash, it.item->key, it.item->key & 1);
+ count += it.get->value / 2;
+ cmap_ii_put(&hash, it.get->key, it.get->key & 1);
} else {
- int one = it.item->key;
- int two = k - it.item->key;
+ int one = it.get->key;
+ int two = k - it.get->key;
cmap_ii_entry_t *hf = cmap_ii_find(&hash, one),
*hs = cmap_ii_emplace(&hash, two, 0).first;
@@ -62,10 +62,10 @@ int findMaximumPairs(int a[], int n, int k) if (one == two) {
// If same then number of pairs will be half
- count += it.item->value / 2;
+ count += it.get->value / 2;
// Check for remaining
- hf->value = (it.item->key & 1);
+ hf->value = (it.get->key & 1);
}
else {
// Store the number of pairs
diff --git a/examples/geek2.c b/examples/geek2.c index a02ede25..8b1ff2aa 100644 --- a/examples/geek2.c +++ b/examples/geek2.c @@ -3,8 +3,8 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
-declare_cset_str();
+cdef_cmap_str();
+cdef_cset_str();
int main()
{
@@ -16,7 +16,7 @@ int main() cset_str_insert(&set, "You");
cset_str_insert(&set, "Tube");
c_foreach (i, cset_str, set)
- printf("%s ", i.item->key.str);
+ printf("%s ", i.get->key.str);
puts("");
// Review some books.
@@ -68,7 +68,7 @@ int main() // Iterate over everything.
c_foreach (i, cmap_str, book_reviews) {
- printf("- %s: \"%s\"\n", i.item->key.str, i.item->value.str);
+ printf("- %s: \"%s\"\n", i.get->key.str, i.get->value.str);
}
cmap_str_destroy(&book_reviews);
}
diff --git a/examples/geek3.c b/examples/geek3.c index 9c959f0e..4e83a8ec 100644 --- a/examples/geek3.c +++ b/examples/geek3.c @@ -3,8 +3,8 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_strkey(si, int);
-declare_cmap_strkey(ss, cstr_t, cstr_destroy);
+cdef_cmap_strkey(si, int);
+cdef_cmap_strkey(ss, cstr_t, cstr_destroy);
int main ()
{
@@ -21,7 +21,7 @@ int main () cmap_si_emplace(&mymap, "Sun", 0).first->value += 1000;
c_foreach (x, cmap_si, mymap) {
- printf("%s: %d\n", x.item->key.str, x.item->value);
+ printf("%s: %d\n", x.get->key.str, x.get->value);
}
cmap_si_destroy(&mymap);
@@ -29,18 +29,18 @@ int main () // Create an unordered_map of three strings (that map to strings)
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"));
+ cmap_ss_put(&u, "RED", cstr("#FF0000"));
+ cmap_ss_put(&u, "GREEN", cstr("#00FF00"));
+ cmap_ss_put(&u, "BLUE", cstr("#0000FF"));
// Iterate and print keys and values of unordered_map
c_foreach (n, cmap_ss, u) {
- printf("%s: %s\n", n.item->key.str, n.item->value.str);
+ printf("%s: %s\n", n.get->key.str, n.get->value.str);
}
// Add two new entries to the unordered_map
- cmap_ss_put(&u, "BLACK", cstr_make("#000000"));
- cmap_ss_put(&u, "WHITE", cstr_make("#FFFFFF"));
+ cmap_ss_put(&u, "BLACK", cstr("#000000"));
+ cmap_ss_put(&u, "WHITE", cstr("#FFFFFF"));
// Output values by key
printf("The HEX of color RED is:[%s]\n", cmap_ss_find(&u, "RED")->value.str);
diff --git a/examples/geek4.c b/examples/geek4.c index ec62efbc..3c4c085f 100644 --- a/examples/geek4.c +++ b/examples/geek4.c @@ -37,9 +37,9 @@ Efficient Approach: For all the words of the first sentence, we can check if it #include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cvec_str();
-declare_cmap_strkey(sb, bool);
-declare_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
+cdef_cvec_str();
+cdef_cmap_strkey(sb, bool);
+cdef_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
// Function to return the count of common words
// in all the sentences
diff --git a/examples/geek5.c b/examples/geek5.c index 614bc387..d8b520c6 100644 --- a/examples/geek5.c +++ b/examples/geek5.c @@ -21,8 +21,8 @@ Output: 0 #include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cvec(i, int);
-declare_cmap_strkey(sv, cvec_i, cvec_i_destroy);
+cdef_cvec(i, int);
+cdef_cmap_strkey(sv, cvec_i, cvec_i_destroy);
// Function to return the number of occurrences of
diff --git a/examples/geek6.c b/examples/geek6.c index badf5bbc..f03053ca 100644 --- a/examples/geek6.c +++ b/examples/geek6.c @@ -30,7 +30,7 @@ operation in almost O(1) time complexity. #include <stdio.h>
#include <stc/cmap.h>
-declare_cset(i, int);
+cdef_cset(i, int);
// Function to find the smallest positive
// missing number
diff --git a/examples/geek7.c b/examples/geek7.c index eb6b61cb..cb0b35a0 100644 --- a/examples/geek7.c +++ b/examples/geek7.c @@ -27,9 +27,9 @@ After inserting all the elements excluding the ones which are to be deleted, Pop #include <stc/cvec.h>
#include <stc/cpqueue.h>
-declare_cmap(ii, int, int);
-declare_cvec(i, int);
-declare_cpqueue(i, cvec_i, >);
+cdef_cmap(ii, int, int);
+cdef_cvec(i, int);
+cdef_cpqueue(i, cvec_i, >);
// Find k minimum element from arr[0..m-1] after deleting
// elements from del[0..n-1]
diff --git a/examples/heap.c b/examples/heap.c index a281de01..fc067a41 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -4,8 +4,8 @@ #include <stc/cvec.h>
#include <stc/cpqueue.h>
-declare_cvec(f, float);
-declare_cpqueue(f, cvec_f, >);
+cdef_cvec(f, float);
+cdef_cpqueue(f, cvec_f, >);
int main()
{
diff --git a/examples/inits.c b/examples/inits.c index 7134c3ff..37b08624 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -5,19 +5,19 @@ #include <stc/cpqueue.h>
#include <stc/clist.h>
-declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-declare_cmap_strkey(cnt, int);
+cdef_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+cdef_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
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);
}
-declare_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
-declare_clist(ip, ipair_t, c_default_destroy, ipair_compare);
+cdef_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
+cdef_clist(ip, ipair_t, c_default_destroy, ipair_compare);
-declare_cvec(f, float);
-declare_cpqueue(f, cvec_f, >);
+cdef_cvec(f, float);
+cdef_cpqueue(f, cvec_f, >);
int main(void) {
@@ -27,7 +27,7 @@ int main(void) { cvec_f floats = cvec_ini;
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);
+ c_foreach (i, cvec_f, floats) printf("%.1f ", *i.get);
puts("");
// CVEC PRIORITY QUEUE
@@ -48,13 +48,13 @@ int main(void) { int year = 2020;
cmap_id idnames = cmap_ini;
c_push(&idnames, cmap_id, {
- {100, cstr_make("Hello")},
- {110, cstr_make("World")},
+ {100, cstr("Hello")},
+ {110, cstr("World")},
{120, cstr_from("Howdy, -%d-", year)},
});
c_foreach (i, cmap_id, idnames)
- printf("%d: %s\n", i.item->key, i.item->value.str);
+ printf("%d: %s\n", i.get->key, i.get->value.str);
puts("");
cmap_id_destroy(&idnames);
@@ -77,7 +77,7 @@ int main(void) { cmap_cnt_emplace(&countries, "Finland", 0).first->value += 20;
c_foreach (i, cmap_cnt, countries)
- printf("%s: %d\n", i.item->key.str, i.item->value);
+ printf("%s: %d\n", i.get->key.str, i.get->value);
puts("");
cmap_cnt_destroy(&countries);
@@ -93,7 +93,7 @@ int main(void) { cvec_ip_sort(&pairs1);
c_foreach (i, cvec_ip, pairs1)
- printf("(%d %d) ", i.item->x, i.item->y);
+ printf("(%d %d) ", i.get->x, i.get->y);
puts("");
cvec_ip_destroy(&pairs1);
@@ -109,7 +109,7 @@ int main(void) { clist_ip_sort(&pairs2);
c_foreach (i, clist_ip, pairs2)
- printf("(%d %d) ", i.item->value.x, i.item->value.y);
+ printf("(%d %d) ", i.get->value.x, i.get->value.y);
puts("");
clist_ip_destroy(&pairs2);
}
\ No newline at end of file diff --git a/examples/list.c b/examples/list.c index d140d103..c77be371 100644 --- a/examples/list.c +++ b/examples/list.c @@ -2,7 +2,7 @@ #include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-declare_clist(fx, double);
+cdef_clist(fx, double);
int main() {
int k, n = 100000;
@@ -13,18 +13,18 @@ int main() { for (int i = 0; i < 100000; ++i)
clist_fx_push_back(&list, crand_uniform_f64(&eng, &dist));
k = 0; c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
k = 0; c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
puts("");
clist_fx_clear(&list);
c_push(&list, clist_fx, {10, 20, 30, 40, 30, 50});
- c_foreach (i, clist_fx, list) printf(" %g", i.item->value);
+ c_foreach (i, clist_fx, list) printf(" %g", i.get->value);
puts("");
int removed = clist_fx_remove(&list, 30);
@@ -34,11 +34,11 @@ int main() { clist_fx_iter_t it = clist_fx_before_begin(&list);
printf("Full: ");
c_foreach (i, clist_fx, list)
- printf(" %g", i.item->value);
+ printf(" %g", i.get->value);
for (int i=0; i<4; ++i) clist_fx_next(&it);
printf("\nSubs: ");
c_foreach (i, clist_fx, it, clist_fx_end(&list))
- printf(" %g", i.item->value);
+ printf(" %g", i.get->value);
puts("");
clist_fx_destroy(&list);
}
\ No newline at end of file diff --git a/examples/mapmap.c b/examples/mapmap.c index f3df9609..4e71f6c0 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -3,8 +3,8 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
-declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
+cdef_cmap_str();
+cdef_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
cmap_cfg config = cmap_ini;
@@ -19,8 +19,8 @@ int main(void) { cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->value, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
- c_foreach (j, cmap_str, i.item->value)
- printf("%s: %s - %s (%u)\n", i.item->key.str, j.item->key.str, j.item->value.str, i.item->value.bucket_count);
+ c_foreach (j, cmap_str, i.get->value)
+ printf("%s: %s - %s (%u)\n", i.get->key.str, j.get->key.str, j.get->value.str, i.get->value.bucket_count);
cmap_cfg_destroy(&config);
}
\ No newline at end of file diff --git a/examples/phonebook.c b/examples/phonebook.c index 983f4e74..716d4e92 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -25,12 +25,12 @@ #include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
+cdef_cmap_str();
void print_phone_book(cmap_str phone_book)
{
c_foreach (i, cmap_str, phone_book)
- printf("%s\t- %s\n", i.item->key.str, i.item->value.str);
+ printf("%s\t- %s\n", i.get->key.str, i.get->value.str);
}
int main(int argc, char **argv)
@@ -47,8 +47,8 @@ int main(int argc, char **argv) printf("Phone book:\n");
print_phone_book(phone_book);
- 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"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1880"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1990"));
printf("\nPhone book after adding Zak Byers:\n");
print_phone_book(phone_book);
diff --git a/examples/priority.c b/examples/priority.c index 8bd2abce..ffc4f97b 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -6,8 +6,8 @@ #include <stc/cmap.h>
#include <stc/crandom.h>
-declare_cvec(i, int64_t);
-declare_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+cdef_cvec(i, int64_t);
+cdef_cpqueue(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
diff --git a/examples/queue.c b/examples/queue.c index 5bac7535..a912d8ea 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -2,8 +2,8 @@ #include <stc/cqueue.h>
#include <stdio.h>
-declare_clist(i, int);
-declare_cqueue(i, clist_i); // min-heap (increasing values)
+cdef_clist(i, int);
+cdef_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
diff --git a/examples/replace.c b/examples/replace.c index 6e5fe024..bcc4952e 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -11,7 +11,7 @@ int main () // replace signatures used in the same order as described above:
// Ustring positions: 0123456789*123456789*12345
- cstr_t s = cstr_make(base); // "this is a test string."
+ cstr_t s = cstr(base); // "this is a test string."
cstr_t m = cstr_clone(s);
cstr_append(&m, m.str);
diff --git a/examples/stack.c b/examples/stack.c index dedf1eb5..a60e5564 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -3,10 +3,10 @@ #include <stc/cstr.h>
#include <stc/cstack.h>
-declare_cvec(i, int);
-declare_cvec(c, char);
-declare_cstack(i, cvec_i);
-declare_cstack(c, cvec_c);
+cdef_cvec(i, int);
+cdef_cvec(c, char);
+cdef_cstack(i, cvec_i);
+cdef_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
diff --git a/examples/words.c b/examples/words.c index 5fc80c62..ad37f72e 100644 --- a/examples/words.c +++ b/examples/words.c @@ -4,9 +4,9 @@ #include <stc/clist.h> #include <stc/cvec.h> -declare_cvec_str(); -declare_clist_str(); -declare_cmap_strkey(si, int); +cdef_cvec_str(); +cdef_clist_str(); +cdef_cmap_strkey(si, int); int main1() @@ -18,7 +18,7 @@ int main1() }); 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); + printf("%s\n", w.get->value.str); puts(""); cvec_str words = cvec_ini; @@ -29,12 +29,12 @@ int main1() cmap_si word_map = cmap_ini; c_foreach (w, cvec_str, words) - cmap_si_emplace(&word_map, w.item->str, 0).first->value += 1; + cmap_si_emplace(&word_map, w.get->str, 0).first->value += 1; c_foreach (pair, cmap_si, word_map) { printf("%d occurrences of word '%s'\n", - pair.item->value, - pair.item->key.str); + pair.get->value, + pair.get->key.str); } cmap_si_destroy(&word_map); |
