1 /* 2 * Copyright 2001, 2002, 2003 David Mansfield and Cobite, Inc. 3 * See COPYING file for license information 4 */ 5 6 #ifndef _COMMON_HASH_H 7 #define _COMMON_HASH_H 8 9 #include "list.h" 10 11 struct hash_entry 12 { 13 char *he_key; 14 void *he_obj; 15 struct list_head he_list; 16 }; 17 18 struct hash_table 19 { 20 int ht_size; 21 struct list_head *ht_lists; 22 int iterator; 23 struct list_head *iterator_ptr; 24 }; 25 26 enum 27 { 28 HT_NO_KEYCOPY, 29 HT_KEYCOPY 30 }; 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 struct hash_table *create_hash_table(unsigned int sz); 37 void destroy_hash_table(struct hash_table *tbl, void (*delete_obj)(void *)); 38 void *put_hash_object(struct hash_table *tbl, const char *key, void *obj); 39 void *get_hash_object(struct hash_table *tbl, const char *key); 40 void *remove_hash_object(struct hash_table *tbl, const char *key); 41 42 int put_hash_object_ex(struct hash_table *tbl, const char *key, void *obj, int, char **, void **); 43 void destroy_hash_table_ex(struct hash_table *tbl, void (*delete_entry)(const void *, char *, void *), const void *); 44 45 void reset_hash_iterator(struct hash_table *tbl); 46 struct hash_entry *next_hash_entry(struct hash_table *tbl); 47 48 #ifdef __cplusplus 49 } 50 #endif 51 52 #endif /* _COMMON_HASH_H */ 53