From a450d0faa8851a7df8dbb52788f99fe216f57c3d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 27 Jan 2009 19:15:51 +0300 Subject: * Add new hash for storing hash data in shared memory * Add rwlocks implementation (primitive) in memory pool library --- src/hash.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/hash.h (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h new file mode 100644 index 000000000..79931a37e --- /dev/null +++ b/src/hash.h @@ -0,0 +1,62 @@ +/* + * ===================================================================================== + * + * Filename: hash.h + * + * Description: Hash table implementation that uses memory pools from mem_pool library + * + * Created: 27.01.2009 16:31:11 + * Compiler: gcc + * + * Author: Vsevolod Stakhov + * Company: Rambler + * + * ===================================================================================== + */ + +#ifndef RSPAMD_HASH_H +#define RSPAMD_HASH_H + +#include +#include +#include "mem_pool.h" + +struct rspamd_hash_node { + gpointer key; + gpointer value; + guint key_hash; + struct rspamd_hash_node *next; +}; + +typedef struct rspamd_hash_s { + gint size; + gint nnodes; + struct rspamd_hash_node **nodes; + + GHashFunc hash_func; + GEqualFunc key_equal_func; + gint shared; + memory_pool_rwlock_t *lock; + memory_pool_t *pool; +} rspamd_hash_t; + +#define rspamd_hash_size(x) (x)->nnodes + +/* Create new hash in specified pool */ +rspamd_hash_t* rspamd_hash_new (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func); +/* Create new hash in specified pool using shared memory */ +rspamd_hash_t* rspamd_hash_new_shared (memory_pool_t *pool, GHashFunc hash_func, GEqualFunc key_equal_func); +/* Insert item in hash */ +void rspamd_hash_insert (rspamd_hash_t *hash, gpointer key, gpointer value); +/* Remove item from hash */ +gboolean rspamd_hash_remove (rspamd_hash_t *hash, gpointer key); +/* Lookup item from hash */ +gpointer rspamd_hash_lookup (rspamd_hash_t *hash, gpointer key); +/* Iterate throught hash */ +void rspamd_hash_foreach (rspamd_hash_t *hash, GHFunc func, gpointer user_data); + +#endif + +/* + * vi:ts=4 + */ -- cgit v1.2.3