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/test14.c |
Squashed 'dependencies/uthash/' content from commit 8e67ced
git-subtree-dir: dependencies/uthash
git-subtree-split: 8e67ced1d1c5bd8141c542a22630e6de78aa6b90
Diffstat (limited to 'tests/test14.c')
-rw-r--r-- | tests/test14.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test14.c b/tests/test14.c new file mode 100644 index 000000000..cb2606716 --- /dev/null +++ b/tests/test14.c @@ -0,0 +1,54 @@ +#include "uthash.h" +#include <stdlib.h> /* malloc */ +#include <errno.h> /* perror */ +#include <stdio.h> /* printf */ + +#define BUFLEN 20 +#if 0 +#undef uthash_expand_fyi +#define uthash_expand_fyi(tbl) printf("expanding to %d buckets\n", tbl->num_buckets) +#endif + +typedef struct name_rec { + char boy_name[BUFLEN]; + UT_hash_handle hh; +} name_rec; + +int main() +{ + name_rec *name, *names=NULL; + char linebuf[BUFLEN]; + FILE *file; + int i=0,j=0; + + file = fopen( "test14.dat", "r" ); + if (file == NULL ) { + perror("can't open: "); + exit(-1); + } + + while (fgets(linebuf,BUFLEN,file) != NULL) { + i++; + name = (name_rec*)malloc(sizeof(name_rec)); + if (name == NULL) { + exit(-1); + } + strcpy(name->boy_name, linebuf); + HASH_ADD_STR(names,boy_name,name); + } + + fseek(file,0L,SEEK_SET); + + while (fgets(linebuf,BUFLEN,file) != NULL) { + HASH_FIND_STR(names,linebuf,name); + if (!name) { + printf("failed to find: %s", linebuf); + } else { + j++; + } + } + fclose(file); + printf("lookup on %d of %d names succeeded\n", j, i); + return 0; +} + |