From 09b696eab6ae640f6c1e07178d49fcd8646e1737 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 19 Dec 2021 20:46:02 +0100 Subject: More docs, small example updates. --- examples/multimap.c | 31 +++++++++++++++---------------- examples/vikings.c | 6 +++--- 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'examples') diff --git a/examples/multimap.c b/examples/multimap.c index 424ae606..472af8aa 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -35,6 +35,21 @@ struct OlympicsData { int year; const char *city, *country, *date; } ol_data[] = typedef struct { int year; cstr city, date; } OlympicLocation; +int OlympicLocation_cmp(OlympicLocation* a, OlympicLocation* b); +OlympicLocation OlympicLocation_clone(OlympicLocation loc); +void OlympicLocation_drop(OlympicLocation* self); + +// Create a clist, can be sorted by year. +#define i_val_bind OlympicLocation // binds _cmp, _clone and _drop. +#define i_tag OL +#include + +// Create a csmap where key is country name +#define i_key_str // binds cstr_equ, cstr_hash, cstr_clone, ++ +#define i_val_bind clist_OL // binds clist_OL_clone, clist_OL_drop +#define i_tag OL +#include + int OlympicLocation_cmp(OlympicLocation* a, OlympicLocation* b) { return a->year - b->year; } @@ -48,22 +63,6 @@ void OlympicLocation_drop(OlympicLocation* self) { c_drop(cstr, &self->city, &self->date); } -// Create a clist, can be sorted by year. -#define i_val OlympicLocation -#define i_cmp OlympicLocation_cmp -#define i_drop OlympicLocation_drop -#define i_from OlympicLocation_clone -#define i_tag OL -#include - -// Create a csmap where key is country name -#define i_key_str -#define i_val clist_OL -#define i_valdrop clist_OL_drop -#define i_valfrom clist_OL_clone -#define i_tag OL -#include - int main() { // Define the multimap with destructor defered to when block is completed. diff --git a/examples/vikings.c b/examples/vikings.c index 87977538..838598b5 100644 --- a/examples/vikings.c +++ b/examples/vikings.c @@ -36,12 +36,12 @@ static inline RViking Viking_toraw(const Viking* vk) { // With this in place, we define the Viking => int hash map type: #define i_type Vikings #define i_key_bind Viking -#define i_val int #define i_keyraw RViking -// i_key_bind auto-maps these functions: +#define i_val int +// i_key_bind auto-binds these functions: // #define i_hash Viking_hash // #define i_equ Viking_equalto -// #define i_keyfrom Viking_from // uses _from because i_keyraw is defined +// #define i_keyfrom Viking_from // uses _from (not _clone) because i_keyraw is defined // #define i_keyto Viking_toraw // #define i_keydrop Viking_drop #include -- cgit v1.2.3