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.

55 lines
1.4KB

  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, *tmp, *users=NULL, *altusers=NULL;
  14. /* create elements */
  15. for(i=0; i<1000; 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. if (i<10) {
  23. HASH_ADD_INT(users,id,user);
  24. }
  25. HASH_ADD(alth,altusers,id,sizeof(int),user);
  26. }
  27. /*
  28. printf("hh items: %d, alth items: %d\n",
  29. users->hh.tbl->num_items, users->alth.tbl->num_items);
  30. printf("hh buckets: %d, alth buckets: %d\n",
  31. users->hh.tbl->num_buckets, users->alth.tbl->num_buckets);
  32. */
  33. i=9;
  34. HASH_FIND_INT(users,&i,tmp);
  35. printf("%d %s in hh\n", i, (tmp != NULL) ? "found" : "not found");
  36. HASH_FIND(alth,altusers,&i,sizeof(int),tmp);
  37. printf("%d %s in alth\n", i, (tmp != NULL) ? "found" : "not found");
  38. i=10;
  39. HASH_FIND_INT(users,&i,tmp);
  40. printf("%d %s in hh\n", i, (tmp != NULL) ? "found" : "not found");
  41. HASH_FIND(alth,altusers,&i,sizeof(int),tmp);
  42. printf("%d %s in alth\n", i, (tmp != NULL) ? "found" : "not found");
  43. HASH_CLEAR(hh, users);
  44. HASH_CLEAR(alth, altusers);
  45. return 0;
  46. }