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.

45 lines
829B

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "uthash.h"
  4. typedef struct {
  5. char a;
  6. int b;
  7. } record_key_t;
  8. typedef struct {
  9. record_key_t key;
  10. /* ... other data ... */
  11. UT_hash_handle hh;
  12. } record_t;
  13. int main()
  14. {
  15. record_t l, *p, *r, *tmp, *records = NULL;
  16. r = (record_t*)malloc( sizeof(record_t) );
  17. if (r == NULL) {
  18. exit(-1);
  19. }
  20. memset(r, 0, sizeof(record_t));
  21. r->key.a = 'a';
  22. r->key.b = 1;
  23. HASH_ADD(hh, records, key, sizeof(record_key_t), r);
  24. memset(&l, 0, sizeof(record_t));
  25. l.key.a = 'a';
  26. l.key.b = 1;
  27. HASH_FIND(hh, records, &l.key, sizeof(record_key_t), p);
  28. if (p != NULL) {
  29. printf("found %c %d\n", p->key.a, p->key.b);
  30. }
  31. HASH_ITER(hh, records, p, tmp) {
  32. HASH_DEL(records, p);
  33. free(p);
  34. }
  35. return 0;
  36. }