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.

70 lines
1.3KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "uthash.h"
  4. typedef struct {
  5. int key;
  6. int data;
  7. UT_hash_handle hh;
  8. } item;
  9. int main()
  10. {
  11. item *i, *j, *items=NULL;
  12. int k;
  13. /* first item */
  14. k = 12345;
  15. i = (item*)malloc(sizeof(item));
  16. if (i == NULL) {
  17. exit(-1);
  18. }
  19. i->key = k;
  20. i->data = 0;
  21. HASH_ADD_INT(items,key,i);
  22. /* second item */
  23. k = 6789;
  24. i = (item*)malloc(sizeof(item));
  25. if (i == NULL) {
  26. exit(-1);
  27. }
  28. i->key = k;
  29. i->data = 0;
  30. HASH_ADD_INT(items,key,i);
  31. /* third item */
  32. k = 98765;
  33. i = (item*)malloc(sizeof(item));
  34. if (i == NULL) {
  35. exit(-1);
  36. }
  37. i->key = k;
  38. i->data = 0;
  39. HASH_ADD_INT(items,key,i);
  40. /* look them all up */
  41. k = 12345;
  42. HASH_FIND_INT(items, &k, j);
  43. if (j != NULL) {
  44. printf("found %d\n",k);
  45. }
  46. k = 6789;
  47. HASH_FIND_INT(items, &k, j);
  48. if (j != NULL) {
  49. printf("found %d\n",k);
  50. }
  51. k = 98765;
  52. HASH_FIND_INT(items, &k, j);
  53. if (j != NULL) {
  54. printf("found %d\n",k);
  55. }
  56. /* delete them not the way we prefer but it works */
  57. for(j=items; j != NULL; j=(item*)j->hh.next) {
  58. printf("deleting %d\n", j->key);
  59. HASH_DEL(items,j);
  60. }
  61. return 0;
  62. }