ticl

tiny irc channel linker
git clone git://git.ircforever.org/ticl
Log | Files | Refs | Submodules | README | LICENSE

htable.h (1276B)


      1 /*
      2  * This work is dedicated to the public domain.
      3  * See COPYING file for more information.
      4  */
      5 
      6 #ifndef HTABLE_H
      7 #define HTABLE_H
      8 
      9 typedef unsigned int	(hash_fn)(void *key, unsigned int cap);
     10 typedef int		(key_cmp_fn)(const void *key1, const void *key2);
     11 typedef void		(key_free_fn)(void *key);
     12 typedef void		(val_free_fn)(void *val);
     13 
     14 struct htnode {
     15 	void		*key;
     16 	void		*val;
     17 	struct htnode	*next;
     18 };
     19 
     20 struct htable {
     21 	struct htnode	**nodes;
     22 	unsigned int	  cap;
     23 	unsigned int	  len;
     24 	hash_fn		 *hash;
     25 	key_cmp_fn	 *key_cmp;
     26 	key_free_fn	 *key_free;
     27 	val_free_fn	 *val_free;
     28 };
     29 
     30 struct htiter {
     31 	unsigned int	 index;
     32 	struct htnode	*node;
     33 };
     34 
     35 struct htable	*htcreate(hash_fn *hash,
     36 			key_cmp_fn *key_cmp,
     37 			key_free_fn *key_free,
     38 			val_free_fn *val_free,
     39 			unsigned int cap);
     40 void		 htdestroy(struct htable *ht);
     41 void		*htsearch(struct htable *ht, void *key);
     42 int		 htinsert(struct htable *ht, void *key, void *val);
     43 int		 htremove(struct htable *ht, void *key);
     44 int		 htmodkey(struct htable *ht, void *oldkey, void *newkey);
     45 int		 htmodval(struct htable *ht, void *key, void *newval);
     46 struct htable	*htresize(struct htable *ht, unsigned int newcap);
     47 void		 htiter_init(struct htiter *it);
     48 int		 htiterate(struct htable *ht, struct htiter *it);
     49 
     50 #endif /* HTABLE_H */