aboutsummaryrefslogtreecommitdiff
path: root/tests/test21.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test21.c')
-rw-r--r--tests/test21.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test21.c b/tests/test21.c
new file mode 100644
index 000000000..b4000df1d
--- /dev/null
+++ b/tests/test21.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "uthash.h"
+
+typedef struct {
+ char a;
+ int b;
+} record_key_t;
+
+typedef struct {
+ record_key_t key;
+ /* ... other data ... */
+ UT_hash_handle hh;
+} record_t;
+
+int main()
+{
+ record_t l, *p, *r, *tmp, *records = NULL;
+
+ r = (record_t*)malloc( sizeof(record_t) );
+ if (r == NULL) {
+ exit(-1);
+ }
+ memset(r, 0, sizeof(record_t));
+ r->key.a = 'a';
+ r->key.b = 1;
+ HASH_ADD(hh, records, key, sizeof(record_key_t), r);
+
+ memset(&l, 0, sizeof(record_t));
+ l.key.a = 'a';
+ l.key.b = 1;
+ HASH_FIND(hh, records, &l.key, sizeof(record_key_t), p);
+
+ if (p != NULL) {
+ printf("found %c %d\n", p->key.a, p->key.b);
+ }
+
+ HASH_ITER(hh, records, p, tmp) {
+ HASH_DEL(records, p);
+ free(p);
+ }
+ return 0;
+}
+