mirror of
https://github.com/utoni/nDPId.git
synced 2026-05-05 19:15:06 +00:00
Merge commit 'c8bf38e5fb' as 'dependencies/uthash'
This commit is contained in:
commit
00e5132a80
250 changed files with 20767 additions and 0 deletions
40
dependencies/uthash/tests/test12.c
vendored
Normal file
40
dependencies/uthash/tests/test12.c
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "uthash.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* malloc */
|
||||
|
||||
typedef struct person_t {
|
||||
char first_name[10];
|
||||
int id;
|
||||
UT_hash_handle hh;
|
||||
} person_t;
|
||||
|
||||
int main()
|
||||
{
|
||||
person_t *people=NULL, *person;
|
||||
const char **name;
|
||||
const char * names[] = { "bob", "jack", "gary", "ty", "bo", "phil", "art",
|
||||
"gil", "buck", "ted", NULL
|
||||
};
|
||||
int id=0;
|
||||
|
||||
for(name=names; *name != NULL; name++) {
|
||||
person = (person_t*)malloc(sizeof(person_t));
|
||||
if (person == NULL) {
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(person->first_name, *name);
|
||||
person->id = id++;
|
||||
HASH_ADD_STR(people,first_name,person);
|
||||
printf("added %s (id %d)\n", person->first_name, person->id);
|
||||
}
|
||||
|
||||
for(name=names; *name != NULL; name++) {
|
||||
HASH_FIND_STR(people,*name,person);
|
||||
if (person != NULL) {
|
||||
printf("found %s (id %d)\n", person->first_name, person->id);
|
||||
} else {
|
||||
printf("failed to find %s\n", *name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue