From c8bf38e5fb717d40635a2a89b22ed71b0de4266b Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Tue, 1 Dec 2020 13:33:34 +0100 Subject: Squashed 'dependencies/uthash/' content from commit 8e67ced git-subtree-dir: dependencies/uthash git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90 --- tests/test20.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test20.c (limited to 'tests/test20.c') diff --git a/tests/test20.c b/tests/test20.c new file mode 100644 index 000000000..9ac01f0ac --- /dev/null +++ b/tests/test20.c @@ -0,0 +1,34 @@ +#include /* memcpy */ +#include /* malloc */ +#include /* printf */ +#include "uthash.h" + +struct my_struct { + char bkey[5]; /* "binary" key */ + int data; + UT_hash_handle hh; +}; + +int main() +{ + struct my_struct *s, *t, *bins = NULL; + char binary[5] = {'\3','\1','\4','\1','\6'}; + + /* allocate our structure. initialize to some values */ + s = (struct my_struct*)calloc(1UL,sizeof(struct my_struct)); + if (s == NULL) { + exit(-1); + } + memcpy(s->bkey, binary, sizeof(binary)); + + /* add to hash table using general macro */ + HASH_ADD( hh, bins, bkey, sizeof(binary), s); + + /* look up the structure we just added */ + HASH_FIND( hh, bins, binary, sizeof(binary), t ); + + if (t != NULL) { + printf("found\n"); + } + return 0; +} -- cgit v1.2.3