diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-12-23 23:14:04 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-12-23 23:14:04 +0100 |
commit | fc2dd1171212f0e72d4169ad2964d0a712dfba23 (patch) | |
tree | 10719d474e128b92dc6615f46f554401a917678c /examples | |
parent | 031bb1d6418236d6b7d581aba48ad8c3864af5c9 (diff) |
Totally rework the gehashmap implementation
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gehashmap.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/examples/gehashmap.c b/examples/gehashmap.c index f216d00..b0763ac 100644 --- a/examples/gehashmap.c +++ b/examples/gehashmap.c @@ -2,18 +2,25 @@ #include <stdlib.h> #include <string.h> -size_t hash(char *); - -#define GEHASHMAP_NAME funmap -#define GEHASHMAP_KEY_T char * -#define GEHASHMAP_VAL_T int -#define GEHASHMAP_CMP_FUNC (int (*)(char *, char *)) strcmp -#define GEHASHMAP_FREE_FUNC (void (*)(char *)) free -#define GEHASHMAP_HASH_FUNC hash #include <gehashmap.h> +GEHASHMAP_API(char *, int, funmap); +GEHASHMAP_IMPL(char *, int, funmap); + +bool +funmap_key_iseq(char *a, char *b) +{ + return strcmp(a, b) == 0; +} + +void +funmap_key_free(char *s) +{ + free(s); +} + size_t -hash(char *s) +funmap_key_hash(char *s) { char c; size_t x = 5381; @@ -31,9 +38,9 @@ main(void) funmap_t *map; funmap_new(map = malloc(sizeof(funmap_t))); - funmap_put(map, strdup("Thomas Voß"), 5); - funmap_put(map, strdup("THOMAS VOẞ"), 6); - funmap_put(map, strdup("Thomas Voss"), 7); + funmap_set(map, strdup("Thomas Voß"), 5); + funmap_set(map, strdup("THOMAS VOẞ"), 6); + funmap_set(map, strdup("Thomas Voss"), 7); funmap_get(map, "Thomas Voß", &n); printf("Thomas Voß -> ‚%d‘\n", n); funmap_get(map, "THOMAS VOẞ", &n); printf("THOMAS VOẞ -> ‚%d‘\n", n); funmap_get(map, "Thomas Voss", &n); printf("Thomas Voss -> ‚%d‘\n", n); |