summaryrefslogtreecommitdiff
path: root/dependencies/uthash/tests/test23.c
diff options
context:
space:
mode:
Diffstat (limited to 'dependencies/uthash/tests/test23.c')
-rw-r--r--dependencies/uthash/tests/test23.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/dependencies/uthash/tests/test23.c b/dependencies/uthash/tests/test23.c
new file mode 100644
index 000000000..132da4207
--- /dev/null
+++ b/dependencies/uthash/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;
+}