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/test23.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test23.c')
-rw-r--r-- | tests/test23.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test23.c b/tests/test23.c new file mode 100644 index 000000000..132da4207 --- /dev/null +++ b/tests/test23.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include "uthash.h" + +typedef struct { + int key; + int data; + UT_hash_handle hh; +} item; + +int main() +{ + item *i, *j, *items=NULL; + int k; + + /* first item */ + k = 12345; + i = (item*)malloc(sizeof(item)); + if (i == NULL) { + exit(-1); + } + i->key = k; + i->data = 0; + HASH_ADD_INT(items,key,i); + + /* second item */ + k = 6789; + i = (item*)malloc(sizeof(item)); + if (i == NULL) { + exit(-1); + } + i->key = k; + i->data = 0; + HASH_ADD_INT(items,key,i); + + /* third item */ + k = 98765; + i = (item*)malloc(sizeof(item)); + if (i == NULL) { + exit(-1); + } + i->key = k; + i->data = 0; + HASH_ADD_INT(items,key,i); + + /* look them all up */ + k = 12345; + HASH_FIND_INT(items, &k, j); + if (j != NULL) { + printf("found %d\n",k); + } + k = 6789; + HASH_FIND_INT(items, &k, j); + if (j != NULL) { + printf("found %d\n",k); + } + k = 98765; + HASH_FIND_INT(items, &k, j); + if (j != NULL) { + printf("found %d\n",k); + } + + /* delete them not the way we prefer but it works */ + for(j=items; j != NULL; j=(item*)j->hh.next) { + printf("deleting %d\n", j->key); + HASH_DEL(items,j); + } + return 0; +} |