7 unsigned int djb_hash(const void *key
)
9 unsigned int i
, hash
= 5381;
10 char *str
= (char *)key
;
12 for (i
= 0; i
< strlen(str
); i
++)
13 hash
= ((hash
<< 5) + hash
) + str
[i
];
15 return (hash
& 0x7FFFFFFF);
18 int mystrcmp(const void *arg1
, const void *arg2
)
20 return (strcmp((char *) arg1
, (char *) arg2
));
23 void myprintf(const void *key
, const void *data
)
25 printf("%s(%s) ", (char *)key
, (char *)data
);
32 /* Initialize table */
33 if (htable_init(&htable
, 2<<5) == HT_NOMEM
) {
38 /* Setup callback functions */
39 htable
.ht_hashf
= djb_hash
;
40 htable
.ht_cmpf
= mystrcmp
;
41 htable
.ht_printf
= myprintf
;
43 htable_insert(&htable
, "stathis", "stathis");
44 htable_insert(&htable
, "maria", "maria");
45 htable_insert(&htable
, "kostas", "kostas");
46 htable_insert(&htable
, "panagiotopoulos", "panagiotopoulos");
47 htable_insert(&htable
, "eleni", "eleni");
48 htable_print(&htable
);
50 htable_remove(&htable
, "maria");
51 htable_print(&htable
);