diff options
| author | Tyge Løvset <[email protected]> | 2022-04-06 18:39:17 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-06 18:39:17 +0200 |
| commit | 3fea4e0b232f7371628944587e561626503fb5fb (patch) | |
| tree | d132bd6ff15ca5bbd469af7bd20dd4e38d2f4526 /examples | |
| parent | d1660bb47cbf3fc0a7066ef1472f2d3bdfeb92b3 (diff) | |
| download | STC-modified-3fea4e0b232f7371628944587e561626503fb5fb.tar.gz STC-modified-3fea4e0b232f7371628944587e561626503fb5fb.zip | |
Refactoring cbits.h and sso alt/cstr.h
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/bits.c | 12 | ||||
| -rw-r--r-- | examples/csmap_insert.c | 14 | ||||
| -rw-r--r-- | examples/sso_map.c | 4 | ||||
| -rw-r--r-- | examples/sso_substr.c | 22 |
4 files changed, 39 insertions, 13 deletions
diff --git a/examples/bits.c b/examples/bits.c index 9fdf1d5d..680b3501 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -17,7 +17,7 @@ int main() printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -27,12 +27,12 @@ int main() cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("\nIterate:");
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
@@ -42,19 +42,19 @@ int main() cbits_set(&s2, 17);
cbits_set(&s2, 18);
printf(" new: ");
- c_forrange (i, int, s2.size)
+ c_forrange (i, s2.size)
printf("%d", cbits_test(s2, i));
puts("");
printf(" xor: ");
cbits_xor(&set, s2);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
cbits_set_all(&set, false);
printf("%4" PRIuMAX ": ", set.size);
- c_forrange (i, int, set.size)
+ c_forrange (i, set.size)
printf("%d", cbits_test(set, i));
puts("");
}
diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index 2a69a8f7..11217de5 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -71,13 +71,16 @@ int main() cvec_ii_push_back(&v, (ipair){44, 311});
puts("Inserting the following vector data into m2:");
- c_foreach (e, cvec_ii, v) printf("(%d, %d) ", e.ref->first, e.ref->second);
+ c_foreach (e, cvec_ii, v)
+ printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("");
- c_foreach (e, cvec_ii, v) csmap_ii_put(&m2, e.ref->first, e.ref->second);
+ c_foreach (e, cvec_ii, v)
+ csmap_ii_insert_or_assign(&m2, e.ref->first, e.ref->second);
puts("The modified key and mapped values of m2 are:");
- c_foreach (e, csmap_ii, m2) printf("(%d, %d) ", e.ref->first, e.ref->second);
+ c_foreach (e, csmap_ii, m2)
+ printf("(%d, %d) ", e.ref->first, e.ref->second);
puts("\n");
}
@@ -99,8 +102,9 @@ int main() c_auto (csmap_ii, m4) {
// Insert the elements from an initializer_list
- c_apply(v, csmap_ii_insert(&m4, c_pair(v)), csmap_ii_raw,
- { { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 } });
+ c_apply(v, csmap_ii_insert(&m4, c_pair(v)), csmap_ii_raw, {
+ { 4, 44 }, { 2, 22 }, { 3, 33 }, { 1, 11 }, { 5, 55 }
+ });
puts("After initializer_list insertion, m4 contains:");
print_ii(m4);
puts("");
diff --git a/examples/sso_map.c b/examples/sso_map.c index 6022572f..a70722f7 100644 --- a/examples/sso_map.c +++ b/examples/sso_map.c @@ -1,5 +1,5 @@ -#include <stc/alt/cstr.h>
-
+#define STC_USE_SSO 1
+#include <stc/cstr.h>
#define i_key_str
#define i_val_str
#include <stc/cmap.h>
diff --git a/examples/sso_substr.c b/examples/sso_substr.c new file mode 100644 index 00000000..60fb9997 --- /dev/null +++ b/examples/sso_substr.c @@ -0,0 +1,22 @@ +#define STC_USE_SSO 1 +#include <stc/cstr.h> +#include <stc/csview.h> + +int main () +{ + cstr str = cstr_new("We think in generalities, but we live in details."); + csview sv1 = cstr_substr(&str, 3, 5); // "think" + size_t pos = cstr_find(str, "live"); // position of "live" + csview sv2 = cstr_substr(&str, pos, 4); // "live" + csview sv3 = cstr_slice(&str, -8, -1); // "details" + printf(c_PRIsv ", " c_PRIsv ", " c_PRIsv "\n", + c_ARGsv(sv1), c_ARGsv(sv2), c_ARGsv(sv3)); + + cstr_assign(&str, "apples are green or red"); + cstr s2 = cstr_from_sv(cstr_substr(&str, -3, 3)); // "red" + cstr s3 = cstr_from_sv(cstr_substr(&str, 0, 6)); // "apples" + printf("%s %s: %d, %d\n", cstr_str(&s2), cstr_str(&s3), + cstr_is_long(&str), cstr_is_long(&s2)); + + c_drop (cstr, &str, &s2, &s3); +} |
