1 /* 2 * This is a public domain general purpose hash table package written by 3 * Peter Moore @ UCB. 4 */ 5 6 /* 7 * @(#) st.h 5.1 89/12/14 8 */ 9 10 #ifndef ST_INCLUDED 11 #define ST_INCLUDED 12 #ifdef __cplusplus 13 extern "C" { 14 #define CLOSE_EXTERN } 15 #else 16 #define CLOSE_EXTERN 17 #endif 18 19 #include <avro/platform.h> /* for uintptr_t */ 20 21 #pragma GCC visibility push(hidden) 22 23 #ifndef ANYARGS 24 #ifdef __cplusplus 25 #define ANYARGS ... 26 #else 27 #define ANYARGS 28 #endif 29 #endif 30 31 #ifdef _WIN32 32 #define HASH_FUNCTION_CAST (int (__cdecl *)(ANYARGS)) 33 #else 34 #define HASH_FUNCTION_CAST 35 #endif 36 37 typedef uintptr_t st_data_t; 38 typedef struct st_table st_table; 39 40 struct st_hash_type { 41 int (*compare) (ANYARGS); 42 int (*hash) (ANYARGS); 43 }; 44 45 struct st_table { 46 struct st_hash_type *type; 47 int num_bins; 48 int num_entries; 49 struct st_table_entry **bins; 50 }; 51 52 #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0) 53 54 enum st_retval { ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK }; 55 56 #ifndef _ 57 # define _(args) args 58 #endif 59 60 st_table *st_init_table _((struct st_hash_type *)); 61 st_table *st_init_table_with_size _((struct st_hash_type *, int)); 62 st_table *st_init_numtable _((void)); 63 st_table *st_init_numtable_with_size _((int)); 64 st_table *st_init_strtable _((void)); 65 st_table *st_init_strtable_with_size _((int)); 66 int st_delete _((st_table *, st_data_t *, st_data_t *)); 67 int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t)); 68 int st_insert _((st_table *, st_data_t, st_data_t)); 69 int st_lookup _((st_table *, st_data_t, st_data_t *)); 70 int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t)); 71 void st_add_direct _((st_table *, st_data_t, st_data_t)); 72 void st_free_table _((st_table *)); 73 void st_cleanup_safe _((st_table *, st_data_t)); 74 st_table *st_copy _((st_table *)); 75 76 #define ST_NUMCMP ((int (*)()) 0) 77 #define ST_NUMHASH ((int (*)()) -2) 78 79 #define st_numcmp ST_NUMCMP 80 #define st_numhash ST_NUMHASH 81 82 int st_strhash(); 83 84 #pragma GCC visibility pop 85 86 CLOSE_EXTERN 87 #endif /* ST_INCLUDED */ 88