From 3868683b6131469a66e365496f93e5a8564e309a Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 8 Sep 2021 16:09:37 +0200 Subject: Adjusted demos.c and multimap.c to work with newstyle branch. --- examples/demos.c | 49 +++++++++++++++++++++++++++---------------------- examples/multimap.c | 16 ++++++++++------ 2 files changed, 37 insertions(+), 28 deletions(-) (limited to 'examples') diff --git a/examples/demos.c b/examples/demos.c index bb4deb22..4c79e357 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -1,11 +1,5 @@ -#include -#include -#include -#include -#include #include - void stringdemo1() { printf("\nSTRINGDEMO1\n"); @@ -34,8 +28,9 @@ void stringdemo1() } } - -using_cvec(ix, int64_t); // ix is just an example tag name. +#define i_tag ix +#define i_val int64_t +#include void vectordemo1() { @@ -58,8 +53,8 @@ void vectordemo1() } } - -using_cvec_str(); +#define i_val_str +#include void vectordemo2() { @@ -77,7 +72,9 @@ void vectordemo2() } } -using_clist(ix, int); +#define i_tag ix +#define i_val int +#include void listdemo1() { @@ -99,7 +96,7 @@ void listdemo1() *clist_ix_find(&nums, 104).ref += 50; clist_ix_remove(&nums, 103); clist_ix_iter_t it = clist_ix_begin(&nums); - clist_ix_erase_range(&nums, clist_ix_fwd(it, 5), clist_ix_fwd(it, 15)); + clist_ix_erase_range(&nums, clist_ix_advance(it, 5), clist_ix_advance(it, 15)); clist_ix_pop_front(&nums); clist_ix_push_back(&nums, -99); clist_ix_sort(&nums); @@ -109,7 +106,9 @@ void listdemo1() } } -using_cset(i, int); +#define i_tag i +#define i_key int +#include void setdemo1() { @@ -123,8 +122,10 @@ void setdemo1() cset_i_del(&nums); } - -using_cmap(ii, int, int); +#define i_tag ii +#define i_key int +#define i_val int +#include void mapdemo1() { @@ -136,8 +137,10 @@ void mapdemo1() cmap_ii_del(&nums); } - -using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expansion. +#define i_tag si +#define i_key_str +#define i_val int +#include void mapdemo2() { @@ -158,8 +161,9 @@ void mapdemo2() } } - -using_cmap_str(); +#define i_key_str +#define i_val_str +#include void mapdemo3() { @@ -181,7 +185,8 @@ void mapdemo3() cmap_str_del(&table); // frees key and value cstrs, and hash table. } - +/* +#include using_carray3(f, float); void arraydemo1() @@ -205,7 +210,7 @@ void arraydemo1() carray3f_del(&arr3); } - +*/ int main() @@ -218,5 +223,5 @@ int main() mapdemo1(); mapdemo2(); mapdemo3(); - arraydemo1(); + //arraydemo1(); } diff --git a/examples/multimap.c b/examples/multimap.c index 03d4712d..eeb7a501 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -35,7 +33,6 @@ struct OlympicsData { int year; const char *city, *country, *date; } ol_data[] = {1924, "Chamonix", "France", "January 25 - February 5"}, }; - typedef struct { int year; cstr city, date; } OlympicLocation; int OlympicLocation_compare(OlympicLocation* a, OlympicLocation* b) { @@ -46,11 +43,18 @@ void OlympicLocation_del(OlympicLocation* self) { } // Create a clist, can be sorted by year. -using_clist(OL, OlympicLocation, OlympicLocation_compare, OlympicLocation_del); +#define i_tag OL +#define i_val OlympicLocation +#define i_cmp OlympicLocation_compare +#define i_valdel OlympicLocation_del +#include // Create a csmap where key is country -using_csmap_strkey(OL, clist_OL, clist_OL_del, c_no_clone); - +#define i_tag OL +#define i_key_str +#define i_val clist_OL +#define i_valdel clist_OL_del +#include int main() { -- cgit v1.2.3