summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-22 15:35:24 +0100
committerGitHub <[email protected]>2020-03-22 15:35:24 +0100
commita0639aa447d2ea63f01a84c5ba8cfc7057d34829 (patch)
tree11dfc82503517558d40438965f0952b28aba52f3
parent012bc0d43e7076d16094c3b87cb7acc344d0581c (diff)
downloadSTC-modified-a0639aa447d2ea63f01a84c5ba8cfc7057d34829.tar.gz
STC-modified-a0639aa447d2ea63f01a84c5ba8cfc7057d34829.zip
Update EXAMPLE.md
-rw-r--r--EXAMPLE.md12
1 files changed, 7 insertions, 5 deletions
diff --git a/EXAMPLE.md b/EXAMPLE.md
index b6a72ef9..efdf1800 100644
--- a/EXAMPLE.md
+++ b/EXAMPLE.md
@@ -29,11 +29,13 @@ void person_destroy(struct Person* p) {
cstring_destroy(&p->surname);
}
-int person_compare(struct Person x, struct Person y) {
+#define person_compareVal(x, y) person_compare(&x, &y)
+
+int person_compare(struct Person* x, struct Person* y) {
int c;
- c = strcmp(x.name.str, y.name.str); if (c != 0) return c;
- c = strcmp(x.surname.str, y.surname.str); if (c != 0) return c;
- return memcmp(&x.age, &y.age, sizeof(x.age));
+ c = strcmp(x->name.str, y->name.str); if (c != 0) return c;
+ c = strcmp(x->surname.str, y->surname.str); if (c != 0) return c;
+ return memcmp(&x->age, &y->age, sizeof(x->age));
}
```
Here is a simple hash function that combines the three member's hashes:
@@ -52,7 +54,7 @@ size_t person_hash(const struct Person* p, size_t ignore) {
With this in place, you can instantiate a CMap with Person => CString:
```
#include <c_lib/CMap.h>
-declare_CMap(ex, struct Person, CString, cstring_destroy, person_hash, person_compare, person_destroy);
+declare_CMap(ex, struct Person, CString, cstring_destroy, person_hash, person_compareVal, person_destroy);
int main()
{