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.

34 lines
791B

  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;
  13. example_user_t *user, *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. for(user=altusers; user != NULL; user=(example_user_t*)(user->alth.next)) {
  26. printf("cookie %d, user %d\n", user->cookie, user->id);
  27. }
  28. return 0;
  29. }