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.

hash.h 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file hash.h
  3. * Hash table implementation that allows using memory pools for storage as well as using
  4. * shared memory for this purpose
  5. */
  6. #ifndef RSPAMD_HASH_H
  7. #define RSPAMD_HASH_H
  8. #include "config.h"
  9. struct rspamd_lru_hash_s;
  10. typedef struct rspamd_lru_hash_s rspamd_lru_hash_t;
  11. struct rspamd_lru_element_s;
  12. typedef struct rspamd_lru_element_s rspamd_lru_element_t;
  13. /**
  14. * Create new lru hash
  15. * @param maxsize maximum elements in a hash
  16. * @param maxage maximum age of elemnt
  17. * @param hash_func pointer to hash function
  18. * @param key_equal_func pointer to function for comparing keys
  19. * @return new rspamd_hash object
  20. */
  21. rspamd_lru_hash_t * rspamd_lru_hash_new (
  22. gint maxsize,
  23. GDestroyNotify key_destroy,
  24. GDestroyNotify value_destroy);
  25. /**
  26. * Create new lru hash
  27. * @param maxsize maximum elements in a hash
  28. * @param maxage maximum age of elemnt
  29. * @param hash_func pointer to hash function
  30. * @param key_equal_func pointer to function for comparing keys
  31. * @return new rspamd_hash object
  32. */
  33. rspamd_lru_hash_t * rspamd_lru_hash_new_full (
  34. gint maxsize,
  35. GDestroyNotify key_destroy,
  36. GDestroyNotify value_destroy,
  37. GHashFunc hfunc,
  38. GEqualFunc eqfunc);
  39. /**
  40. * Lookup item from hash
  41. * @param hash hash object
  42. * @param key key to find
  43. * @return value of key or NULL if key is not found
  44. */
  45. gpointer rspamd_lru_hash_lookup (rspamd_lru_hash_t *hash,
  46. gconstpointer key,
  47. time_t now);
  48. /**
  49. * Removes key from LRU cache
  50. * @param hash
  51. * @param key
  52. * @return TRUE if key has been found and removed
  53. */
  54. gboolean rspamd_lru_hash_remove (rspamd_lru_hash_t *hash,
  55. gconstpointer key);
  56. /**
  57. * Insert item in hash
  58. * @param hash hash object
  59. * @param key key to insert
  60. * @param value value of key
  61. */
  62. void rspamd_lru_hash_insert (rspamd_lru_hash_t *hash,
  63. gpointer key,
  64. gpointer value,
  65. time_t now,
  66. guint ttl);
  67. /**
  68. * Remove lru hash
  69. * @param hash hash object
  70. */
  71. void rspamd_lru_hash_destroy (rspamd_lru_hash_t *hash);
  72. /**
  73. * Get hash table for this lru hash (use rspamd_lru_element_t as data)
  74. */
  75. GHashTable *rspamd_lru_hash_get_htable (rspamd_lru_hash_t *hash);
  76. /**
  77. * Get element's data
  78. * @param elt
  79. * @return
  80. */
  81. gpointer rspamd_lru_hash_element_data (rspamd_lru_element_t *elt);
  82. #endif
  83. /*
  84. * vi:ts=4
  85. */