Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
979B

  1. #include "uthash.h"
  2. #include <stdlib.h> /* malloc */
  3. #include <stdio.h> /* printf */
  4. typedef struct example_user_t {
  5. int id;
  6. int cookie;
  7. UT_hash_handle hh;
  8. UT_hash_handle alth;
  9. } example_user_t;
  10. int main()
  11. {
  12. int i,j;
  13. example_user_t *user, *tmp, *users=NULL, *altusers=NULL;
  14. /* create elements */
  15. for(i=0; i<10; i++) {
  16. user = (example_user_t*)malloc(sizeof(example_user_t));
  17. if (user == NULL) {
  18. exit(-1);
  19. }
  20. user->id = i;
  21. user->cookie = i*i;
  22. HASH_ADD_INT(users,id,user);
  23. HASH_ADD(alth,altusers,cookie,sizeof(int),user);
  24. }
  25. /* find cookie corresponding to each even ID */
  26. for(i=0; i<10; i+=2) {
  27. j=i*i;
  28. HASH_FIND(alth,altusers,&j,sizeof(int),tmp);
  29. if (tmp != NULL) {
  30. printf("cookie %d found, user id %d\n", tmp->cookie, tmp->id);
  31. } else {
  32. printf("cookie %d not found\n", j);
  33. }
  34. }
  35. return 0;
  36. }