diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2020-12-01 13:33:34 +0100 |
commit | c8bf38e5fb717d40635a2a89b22ed71b0de4266b (patch) | |
tree | 63751b2f5497c6f99e1c6a78f23a8e6e5c49833f /tests/test39.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test39.c')
-rw-r--r-- | tests/test39.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test39.c b/tests/test39.c new file mode 100644 index 000000000..18a0af8b4 --- /dev/null +++ b/tests/test39.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include "uthash.h" + +typedef struct { + const char *name; + UT_hash_handle hh; +} ns_t; + +int main() +{ + const char *keys[] = {"eins", "zwei", "drei"}; + unsigned i; + ns_t *nsp; + ns_t *head = NULL; + + for(i=0; i < (sizeof(keys)/sizeof(keys[0])); i++) { + printf("adding key %s\n", keys[i]); + nsp = (ns_t*)malloc(sizeof(ns_t)); + if (nsp == NULL) { + exit(-1); + } + nsp->name = keys[i]; + HASH_ADD_KEYPTR(hh,head,nsp->name,strlen(nsp->name),nsp); + } + printf("hash count is %u\n", HASH_COUNT(head)); + + for(i=0; i < (sizeof(keys)/sizeof(keys[0])); i++) { + printf("looking for key %s... ", keys[i]); + HASH_FIND(hh,head,keys[i],strlen(keys[i]),nsp); + printf("%s.\n", (nsp!=NULL)?"found":"not found"); + } + return 0; +} |