#include #include #include #include GEHASHMAP_API(char *, int, atoimap); GEHASHMAP_API(int, unsigned int, itoumap); GEHASHMAP_IMPL(char *, int, atoimap); GEHASHMAP_IMPL(int, unsigned int, itoumap); bool atoimap_key_iseq(char *a, char *b) { return strcmp(a, b) == 0; } bool itoumap_key_iseq(int a, int b) { return a == b; } void atoimap_key_free(char *s) { free(s); } void itoumap_key_free(int a) { (void) a; } size_t atoimap_key_hash(char *s) { char c; size_t x = 5381; while (c = *s++) x = ((x << 5) + x) + c; return x; } size_t itoumap_key_hash(int n) { return n; } int main(void) { int i; unsigned int u; atoimap_t *map_a; itoumap_t *map_b; atoimap_new(map_a = malloc(sizeof(atoimap_t))); itoumap_new(map_b = malloc(sizeof(itoumap_t))); atoimap_set(map_a, "Thomas Voß", 5); atoimap_set(map_a, "THOMAS VOẞ", 6); atoimap_set(map_a, "Thomas Voss", 7); atoimap_get(map_a, "Thomas Voß", &i); printf("Thomas Voß -> %d\n", i); atoimap_get(map_a, "THOMAS VOẞ", &i); printf("THOMAS VOẞ -> %d\n", i); atoimap_get(map_a, "Thomas Voss", &i); printf("Thomas Voss -> %d\n", i); itoumap_set(map_b, -42, +42); itoumap_set(map_b, -69, +69); itoumap_set(map_b, -420, +420); /* Inefficient */ if (itoumap_has(map_b, -21)) { itoumap_get(map_b, -21, &u); printf("%d -> %u\n", -21, u); } /* Efficient */ if (itoumap_get(map_b, -42, &u)) printf("%d -> %u\n", -42, u); if (itoumap_get(map_b, -69, &u)) printf("%d -> %u\n", -69, u); itoumap_remove(map_b, -420); if (itoumap_get(map_b, -420, &u)) printf("%d -> %u\n", -420, u); atoimap_free(map_a); itoumap_free(map_b); free(map_a); free(map_b); }