diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-10 16:42:07 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-10-10 16:42:07 +0400 |
commit | 25769904acc693327d9ae40e329fc8bd93ae43bc (patch) | |
tree | b7e4715715a3430b136d4c6c3ed92853dd24a46a /src/hash.h | |
parent | 2c7e49f97e737af5ac40bef8bf2b33fa9331736f (diff) | |
download | rspamd-25769904acc693327d9ae40e329fc8bd93ae43bc.tar.gz rspamd-25769904acc693327d9ae40e329fc8bd93ae43bc.zip |
* LRU cache now is capable to get custom insert and delete functions that would allow to use custom storage engines for it0.4.4
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/hash.h b/src/hash.h index 1625aaba1..fc336b6bb 100644 --- a/src/hash.h +++ b/src/hash.h @@ -28,12 +28,22 @@ typedef struct rspamd_hash_s { memory_pool_t *pool; } rspamd_hash_t; +typedef void (*lru_cache_insert_func)(gpointer storage, gpointer key, gpointer value); +typedef gpointer (*lru_cache_lookup_func)(gpointer storage, gpointer key); +typedef gboolean (*lru_cache_delete_func)(gpointer storage, gpointer key); +typedef void (*lru_cache_destroy_func)(gpointer storage); + typedef struct rspamd_lru_hash_s { gint maxsize; gint maxage; - GHashTable *storage; GDestroyNotify value_destroy; + GDestroyNotify key_destroy; GQueue *q; + gpointer storage; + lru_cache_insert_func insert_func; + lru_cache_lookup_func lookup_func; + lru_cache_delete_func delete_func; + lru_cache_destroy_func destroy_func; } rspamd_lru_hash_t; typedef struct rspamd_lru_element_s { @@ -105,6 +115,19 @@ void rspamd_hash_foreach (rspamd_hash_t *hash, GHFunc func, gpointer user_data); */ rspamd_lru_hash_t* rspamd_lru_hash_new (GHashFunc hash_func, GEqualFunc key_equal_func, gint maxsize, gint maxage, GDestroyNotify key_destroy, GDestroyNotify value_destroy); + +/** + * Create new lru hash with custom storage + * @param maxsize maximum elements in a hash + * @param maxage maximum age of elemnt + * @param hash_func pointer to hash function + * @param key_equal_func pointer to function for comparing keys + * @return new rspamd_hash object + */ +rspamd_lru_hash_t* rspamd_lru_hash_new_full (GHashFunc hash_func, GEqualFunc key_equal_func, + gint maxsize, gint maxage, GDestroyNotify key_destroy, GDestroyNotify value_destroy, + gpointer storage, lru_cache_insert_func insert_func, lru_cache_lookup_func lookup_func, + lru_cache_delete_func delete_func); /** * Lookup item from hash * @param hash hash object |