lhash.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #ifndef HEADER_LHASH_H
00064 #define HEADER_LHASH_H
00065
00066 #include <openssl/e_os2.h>
00067 #ifndef OPENSSL_NO_FP_API
00068 #include <stdio.h>
00069 #endif
00070
00071 #ifndef OPENSSL_NO_BIO
00072 #include <openssl/bio.h>
00073 #endif
00074
00075 #ifdef __cplusplus
00076 extern "C" {
00077 #endif
00078
00079 typedef struct lhash_node_st
00080 {
00081 void *data;
00082 struct lhash_node_st *next;
00083 #ifndef OPENSSL_NO_HASH_COMP
00084 unsigned long hash;
00085 #endif
00086 } LHASH_NODE;
00087
00088 typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
00089 typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
00090 typedef void (*LHASH_DOALL_FN_TYPE)(void *);
00091 typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 #define DECLARE_LHASH_HASH_FN(f_name,o_type) \
00102 unsigned long f_name##_LHASH_HASH(const void *);
00103 #define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
00104 unsigned long f_name##_LHASH_HASH(const void *arg) { \
00105 o_type a = (o_type)arg; \
00106 return f_name(a); }
00107 #define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
00108
00109
00110 #define DECLARE_LHASH_COMP_FN(f_name,o_type) \
00111 int f_name##_LHASH_COMP(const void *, const void *);
00112 #define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
00113 int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
00114 o_type a = (o_type)arg1; \
00115 o_type b = (o_type)arg2; \
00116 return f_name(a,b); }
00117 #define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
00118
00119
00120 #define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
00121 void f_name##_LHASH_DOALL(void *);
00122 #define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
00123 void f_name##_LHASH_DOALL(void *arg) { \
00124 o_type a = (o_type)arg; \
00125 f_name(a); }
00126 #define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
00127
00128
00129 #define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
00130 void f_name##_LHASH_DOALL_ARG(void *, void *);
00131 #define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
00132 void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
00133 o_type a = (o_type)arg1; \
00134 a_type b = (a_type)arg2; \
00135 f_name(a,b); }
00136 #define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
00137
00138 typedef struct lhash_st
00139 {
00140 LHASH_NODE **b;
00141 LHASH_COMP_FN_TYPE comp;
00142 LHASH_HASH_FN_TYPE hash;
00143 unsigned int num_nodes;
00144 unsigned int num_alloc_nodes;
00145 unsigned int p;
00146 unsigned int pmax;
00147 unsigned long up_load;
00148 unsigned long down_load;
00149 unsigned long num_items;
00150
00151 unsigned long num_expands;
00152 unsigned long num_expand_reallocs;
00153 unsigned long num_contracts;
00154 unsigned long num_contract_reallocs;
00155 unsigned long num_hash_calls;
00156 unsigned long num_comp_calls;
00157 unsigned long num_insert;
00158 unsigned long num_replace;
00159 unsigned long num_delete;
00160 unsigned long num_no_delete;
00161 unsigned long num_retrieve;
00162 unsigned long num_retrieve_miss;
00163 unsigned long num_hash_comps;
00164
00165 int error;
00166 } LHASH;
00167
00168 #define LH_LOAD_MULT 256
00169
00170
00171
00172 #define lh_error(lh) ((lh)->error)
00173
00174 LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
00175 void lh_free(LHASH *lh);
00176 void *lh_insert(LHASH *lh, void *data);
00177 void *lh_delete(LHASH *lh, const void *data);
00178 void *lh_retrieve(LHASH *lh, const void *data);
00179 void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
00180 void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
00181 unsigned long lh_strhash(const char *c);
00182 unsigned long lh_num_items(const LHASH *lh);
00183
00184 #ifndef OPENSSL_NO_FP_API
00185 void lh_stats(const LHASH *lh, FILE *out);
00186 void lh_node_stats(const LHASH *lh, FILE *out);
00187 void lh_node_usage_stats(const LHASH *lh, FILE *out);
00188 #endif
00189
00190 #ifndef OPENSSL_NO_BIO
00191 void lh_stats_bio(const LHASH *lh, BIO *out);
00192 void lh_node_stats_bio(const LHASH *lh, BIO *out);
00193 void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
00194 #endif
00195 #ifdef __cplusplus
00196 }
00197 #endif
00198
00199 #endif
00200