summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-19 20:46:02 +0100
committerTyge Løvset <[email protected]>2021-12-19 20:46:02 +0100
commit09b696eab6ae640f6c1e07178d49fcd8646e1737 (patch)
treeb3858126f9cfce10075c06267b73af596e6d58c4 /examples
parentfd9386222ab102fac57834646b34d4a5014b1588 (diff)
downloadSTC-modified-09b696eab6ae640f6c1e07178d49fcd8646e1737.tar.gz
STC-modified-09b696eab6ae640f6c1e07178d49fcd8646e1737.zip
More docs, small example updates.
Diffstat (limited to 'examples')
-rw-r--r--examples/multimap.c31
-rw-r--r--examples/vikings.c6
2 files changed, 18 insertions, 19 deletions
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<OlympicLocation>, can be sorted by year.
+#define i_val_bind OlympicLocation // binds _cmp, _clone and _drop.
+#define i_tag OL
+#include <stc/clist.h>
+
+// Create a csmap<cstr, clist_OL> 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 <stc/csmap.h>
+
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<OlympicLocation>, 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 <stc/clist.h>
-
-// Create a csmap<cstr, clist_OL> 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 <stc/csmap.h>
-
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 <stc/cmap.h>