7 int ivals[] = {0,1,2,3,4,5,6,7,8,9};
9 unsigned long djb2hash(const void *x)
12 unsigned long hash = 5381;
16 while ( (c = *str++) )
21 int scmp(const void *a, const void *b, void *aux)
27 void myfree(void *a, void *aux)
35 hashmap *h = hm_new(0, djb2hash, scmp, NULL);
36 assert(hm_length(h) == 0);
37 assert(hm_is_empty(h));
39 assert(!hm_at(h, "zero"));
40 hm_insert(h, "zero", ivals);
41 assert(hm_length(h) == 1);
42 assert(*(int*)hm_at(h, "zero") == 0);
44 hm_insert(h, "one", ivals+1);
45 assert(hm_length(h) == 2);
46 assert(*(int*)hm_at(h, "zero") == 0);
47 assert(*(int*)hm_at(h, "one") == 1);
48 assert(!hm_at(h, "flurgle"));
51 assert(!hm_at(h, "one"));
54 assert(hm_length(h) == 0);
55 assert(!hm_at(h, "zero"));
57 /* test for memory leak */
58 hm_dtor(h, NULL, myfree, NULL);
59 int *life = malloc(sizeof *life);
61 hm_insert(h, "life", life);