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.

35 lines
849B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "uthash.h"
  4. typedef struct {
  5. const char *name;
  6. UT_hash_handle hh;
  7. } ns_t;
  8. int main()
  9. {
  10. const char *keys[] = {"eins", "zwei", "drei"};
  11. unsigned i;
  12. ns_t *nsp;
  13. ns_t *head = NULL;
  14. for(i=0; i < (sizeof(keys)/sizeof(keys[0])); i++) {
  15. printf("adding key %s\n", keys[i]);
  16. nsp = (ns_t*)malloc(sizeof(ns_t));
  17. if (nsp == NULL) {
  18. exit(-1);
  19. }
  20. nsp->name = keys[i];
  21. HASH_ADD_KEYPTR(hh,head,nsp->name,strlen(nsp->name),nsp);
  22. }
  23. printf("hash count is %u\n", HASH_COUNT(head));
  24. for(i=0; i < (sizeof(keys)/sizeof(keys[0])); i++) {
  25. printf("looking for key %s... ", keys[i]);
  26. HASH_FIND(hh,head,keys[i],strlen(keys[i]),nsp);
  27. printf("%s.\n", (nsp!=NULL)?"found":"not found");
  28. }
  29. return 0;
  30. }