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.

72 lines
1.5KB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "uthash.h"
  4. typedef struct hs_t {
  5. int id;
  6. int tag;
  7. UT_hash_handle hh;
  8. } hs_t;
  9. static void pr(hs_t **hdpp)
  10. {
  11. hs_t *el, *tmp, *hdp = *hdpp;
  12. HASH_ITER(hh, hdp, el, tmp) {
  13. printf("id %d, tag %d\n",el->id,el->tag);
  14. }
  15. }
  16. int main()
  17. {
  18. hs_t *hs_head=NULL, *tmp, *replaced=NULL;
  19. tmp = (hs_t*)malloc(sizeof(hs_t));
  20. if (tmp == NULL) {
  21. exit(-1);
  22. }
  23. tmp->id = 10;
  24. tmp->tag = 100;
  25. HASH_REPLACE_INT(hs_head,id,tmp,replaced);
  26. if(replaced == NULL) {
  27. printf("added %d %d\n",tmp->id,tmp->tag);
  28. } else {
  29. printf("ERROR, ended up replacing a value, replaced: %p\n",(void*)replaced);
  30. }
  31. pr(&hs_head);
  32. tmp = (hs_t*)malloc(sizeof(hs_t));
  33. if (tmp == NULL) {
  34. exit(-1);
  35. }
  36. tmp->id=11;
  37. tmp->tag = 101;
  38. HASH_REPLACE_INT(hs_head,id,tmp,replaced);
  39. if(replaced == NULL) {
  40. printf("added %d %d\n",tmp->id,tmp->tag);
  41. } else {
  42. printf("ERROR, ended up replacing a value, replaced: %p\n",(void*)replaced);
  43. }
  44. pr(&hs_head);
  45. tmp = (hs_t*)malloc(sizeof(hs_t));
  46. if (tmp == NULL) {
  47. exit(-1);
  48. }
  49. tmp->id=11;
  50. tmp->tag = 102;
  51. HASH_REPLACE_INT(hs_head,id,tmp,replaced);
  52. if(replaced == NULL) {
  53. printf("ERROR, exected to replace a value with key: %d\n",tmp->id);
  54. } else {
  55. printf("replaced %d that had tag %d with tag %d\n",tmp->id,replaced->tag,tmp->tag);
  56. }
  57. pr(&hs_head);
  58. return 0;
  59. }