hashmap.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * hashmap.h
  3. *
  4. * Created on: 2019�~4��27��
  5. * Author: foluswen
  6. */
  7. #ifndef HASHMAP_H_
  8. #define HASHMAP_H_
  9. #define KEY_COUNT (1024*1024)
  10. #define KEY_MAX_LENGTH (37)
  11. #define VALUE_MAX_LENGTH (65)
  12. #define MAP_MISSING -3 /* No such element */
  13. #define MAP_FULL -2 /* Hashmap is full */
  14. #define MAP_OMEM -1 /* Out of Memory */
  15. #define MAP_OK 0 /* OK */
  16. typedef struct data_struct_s
  17. {
  18. char key_string[KEY_MAX_LENGTH];
  19. char key_value[VALUE_MAX_LENGTH];
  20. } data_struct_t;
  21. /*
  22. * any_t is a pointer. This allows you to put arbitrary structures in
  23. * the hashmap.
  24. */
  25. typedef void *any_t;
  26. //typedef void any_t;
  27. /*
  28. * PFany is a pointer to a function that can take two any_t arguments
  29. * and return an integer. Returns status code..
  30. */
  31. typedef int (*PFany)(any_t, any_t);
  32. /*
  33. * map_t is a pointer to an internally maintained data structure.
  34. * Clients of this package do not need to know how hashmaps are
  35. * represented. They see and manipulate only map_t's.
  36. */
  37. typedef any_t map_t;
  38. /*
  39. * Return an empty hashmap. Returns NULL if empty.
  40. */
  41. extern map_t hashmap_new();
  42. /*
  43. * Iteratively call f with argument (item, data) for
  44. * each element data in the hashmap. The function must
  45. * return a map status code. If it returns anything other
  46. * than MAP_OK the traversal is terminated. f must
  47. * not reenter any hashmap functions, or deadlock may arise.
  48. */
  49. extern int hashmap_iterate(map_t in, PFany f, any_t item);
  50. /*
  51. * Add an element to the hashmap. Return MAP_OK or MAP_OMEM.
  52. */
  53. extern int hashmap_put(map_t in, char* key, any_t value);
  54. /*
  55. * Get an element from the hashmap. Return MAP_OK or MAP_MISSING.
  56. */
  57. extern int hashmap_get(map_t in, char* key, any_t *arg);
  58. /*
  59. * Remove an element from the hashmap. Return MAP_OK or MAP_MISSING.
  60. */
  61. extern int hashmap_remove(map_t in, char* key);
  62. /*
  63. * Get any element. Return MAP_OK or MAP_MISSING.
  64. * remove - should the element be removed from the hashmap
  65. */
  66. extern int hashmap_get_one(map_t in, any_t *arg, int remove);
  67. /*
  68. * Free the hashmap
  69. */
  70. extern void hashmap_free(map_t in);
  71. /*
  72. * Get the current size of a hashmap
  73. */
  74. extern int hashmap_length(map_t in);
  75. /*
  76. * hashmap_operation operation
  77. */
  78. //extern int hashmap_operation(int type, map_t in, char* key, any_t value, any_t *arg);
  79. extern int hashmap_operation(int type, char *uuid, char *data);
  80. /*
  81. * hashmapForMessageNew operation
  82. */
  83. extern void hashmapForMessageNew(void);
  84. /*
  85. * hashmapForMessageFree operation
  86. */
  87. extern void hashmapForMessageFree(void);
  88. /*
  89. * hashmapForMessageFree operation
  90. */
  91. extern int hashmapForMessageLength(void);
  92. #endif /* HASHMAP_H_ */