1 /*
2  * This file is part of the zlog Library.
3  *
4  * Copyright (C) 2011 by Hardy Simpson <HardySimpson1984@gmail.com>
5  *
6  * Licensed under the LGPL v2.1, see the file COPYING in base directory.
7  */
8 
9 #ifndef __zc_hashtalbe_h
10 #define __zc_hashtalbe_h
11 
12 #include <stdlib.h>
13 
14 typedef struct zc_hashtable_entry_s {
15 	unsigned int hash_key;
16 	void *key;
17 	void *value;
18 	struct zc_hashtable_entry_s *prev;
19 	struct zc_hashtable_entry_s *next;
20 } zc_hashtable_entry_t;
21 
22 typedef struct zc_hashtable_s zc_hashtable_t;
23 
24 typedef unsigned int (*zc_hashtable_hash_fn) (const void *key);
25 typedef int (*zc_hashtable_equal_fn) (const void *key1, const void *key2);
26 typedef void (*zc_hashtable_del_fn) (void *kv);
27 
28 zc_hashtable_t *zc_hashtable_new(size_t a_size,
29 				 zc_hashtable_hash_fn hash_fn,
30 				 zc_hashtable_equal_fn equal_fn,
31 				 zc_hashtable_del_fn key_del_fn,
32 				 zc_hashtable_del_fn value_del_fn);
33 
34 void zc_hashtable_del(zc_hashtable_t * a_table);
35 void zc_hashtable_clean(zc_hashtable_t * a_table);
36 int zc_hashtable_put(zc_hashtable_t * a_table, void *a_key, void *a_value);
37 zc_hashtable_entry_t *zc_hashtable_get_entry(zc_hashtable_t * a_table, const void *a_key);
38 void *zc_hashtable_get(zc_hashtable_t * a_table, const void *a_key);
39 void zc_hashtable_remove(zc_hashtable_t * a_table, const void *a_key);
40 zc_hashtable_entry_t *zc_hashtable_begin(zc_hashtable_t * a_table);
41 zc_hashtable_entry_t *zc_hashtable_next(zc_hashtable_t * a_table, zc_hashtable_entry_t * a_entry);
42 
43 #define zc_hashtable_foreach(a_table, a_entry) \
44 for(a_entry = zc_hashtable_begin(a_table); a_entry; a_entry = zc_hashtable_next(a_table, a_entry))
45 
46 unsigned int zc_hashtable_str_hash(const void *str);
47 int zc_hashtable_str_equal(const void *key1, const void *key2);
48 
49 #endif
50