aboutsummaryrefslogtreecommitdiff
path: root/tests/test21.c
blob: b4000df1db4e5dd82aefe2ec1690784ac08ade97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}