1 /* crypto/lhash/lhash.h */
\r
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
\r
3 * All rights reserved.
\r
5 * This package is an SSL implementation written
\r
6 * by Eric Young (eay@cryptsoft.com).
\r
7 * The implementation was written so as to conform with Netscapes SSL.
\r
9 * This library is free for commercial and non-commercial use as long as
\r
10 * the following conditions are aheared to. The following conditions
\r
11 * apply to all code found in this distribution, be it the RC4, RSA,
\r
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
\r
13 * included with this distribution is covered by the same copyright terms
\r
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
\r
16 * Copyright remains Eric Young's, and as such any Copyright notices in
\r
17 * the code are not to be removed.
\r
18 * If this package is used in a product, Eric Young should be given attribution
\r
19 * as the author of the parts of the library used.
\r
20 * This can be in the form of a textual message at program startup or
\r
21 * in documentation (online or textual) provided with the package.
\r
23 * Redistribution and use in source and binary forms, with or without
\r
24 * modification, are permitted provided that the following conditions
\r
26 * 1. Redistributions of source code must retain the copyright
\r
27 * notice, this list of conditions and the following disclaimer.
\r
28 * 2. Redistributions in binary form must reproduce the above copyright
\r
29 * notice, this list of conditions and the following disclaimer in the
\r
30 * documentation and/or other materials provided with the distribution.
\r
31 * 3. All advertising materials mentioning features or use of this software
\r
32 * must display the following acknowledgement:
\r
33 * "This product includes cryptographic software written by
\r
34 * Eric Young (eay@cryptsoft.com)"
\r
35 * The word 'cryptographic' can be left out if the rouines from the library
\r
36 * being used are not cryptographic related :-).
\r
37 * 4. If you include any Windows specific code (or a derivative thereof) from
\r
38 * the apps directory (application code) you must include an acknowledgement:
\r
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
\r
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
\r
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
\r
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
53 * The licence and distribution terms for any publically available version or
\r
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
\r
55 * copied and put under another distribution licence
\r
56 * [including the GNU Public Licence.]
\r
59 /* Header for dynamic hash table routines
\r
60 * Author - Eric Young
\r
63 #ifndef HEADER_LHASH_H
\r
64 #define HEADER_LHASH_H
\r
66 #include <openssl/e_os2.h>
\r
67 #ifndef OPENSSL_NO_FP_API
\r
71 #ifndef OPENSSL_NO_BIO
\r
72 #include <openssl/bio.h>
\r
79 typedef struct lhash_node_st
\r
82 struct lhash_node_st *next;
\r
83 #ifndef OPENSSL_NO_HASH_COMP
\r
88 typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
\r
89 typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
\r
90 typedef void (*LHASH_DOALL_FN_TYPE)(void *);
\r
91 typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
\r
93 /* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
\r
94 * This way, callbacks can be provided to LHASH structures without function
\r
95 * pointer casting and the macro-defined callbacks provide per-variable casting
\r
96 * before deferring to the underlying type-specific callbacks. NB: It is
\r
97 * possible to place a "static" in front of both the DECLARE and IMPLEMENT
\r
98 * macros if the functions are strictly internal. */
\r
100 /* First: "hash" functions */
\r
101 #define DECLARE_LHASH_HASH_FN(f_name,o_type) \
\r
102 unsigned long f_name##_LHASH_HASH(const void *);
\r
103 #define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
\r
104 unsigned long f_name##_LHASH_HASH(const void *arg) { \
\r
105 o_type a = (o_type)arg; \
\r
106 return f_name(a); }
\r
107 #define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
\r
109 /* Second: "compare" functions */
\r
110 #define DECLARE_LHASH_COMP_FN(f_name,o_type) \
\r
111 int f_name##_LHASH_COMP(const void *, const void *);
\r
112 #define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
\r
113 int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
\r
114 o_type a = (o_type)arg1; \
\r
115 o_type b = (o_type)arg2; \
\r
116 return f_name(a,b); }
\r
117 #define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
\r
119 /* Third: "doall" functions */
\r
120 #define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
\r
121 void f_name##_LHASH_DOALL(void *);
\r
122 #define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
\r
123 void f_name##_LHASH_DOALL(void *arg) { \
\r
124 o_type a = (o_type)arg; \
\r
126 #define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
\r
128 /* Fourth: "doall_arg" functions */
\r
129 #define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
\r
130 void f_name##_LHASH_DOALL_ARG(void *, void *);
\r
131 #define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
\r
132 void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
\r
133 o_type a = (o_type)arg1; \
\r
134 a_type b = (a_type)arg2; \
\r
136 #define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
\r
138 typedef struct lhash_st
\r
141 LHASH_COMP_FN_TYPE comp;
\r
142 LHASH_HASH_FN_TYPE hash;
\r
143 unsigned int num_nodes;
\r
144 unsigned int num_alloc_nodes;
\r
147 unsigned long up_load; /* load times 256 */
\r
148 unsigned long down_load; /* load times 256 */
\r
149 unsigned long num_items;
\r
151 unsigned long num_expands;
\r
152 unsigned long num_expand_reallocs;
\r
153 unsigned long num_contracts;
\r
154 unsigned long num_contract_reallocs;
\r
155 unsigned long num_hash_calls;
\r
156 unsigned long num_comp_calls;
\r
157 unsigned long num_insert;
\r
158 unsigned long num_replace;
\r
159 unsigned long num_delete;
\r
160 unsigned long num_no_delete;
\r
161 unsigned long num_retrieve;
\r
162 unsigned long num_retrieve_miss;
\r
163 unsigned long num_hash_comps;
\r
168 #define LH_LOAD_MULT 256
\r
170 /* Indicates a malloc() error in the last call, this is only bad
\r
171 * in lh_insert(). */
\r
172 #define lh_error(lh) ((lh)->error)
\r
174 LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
\r
175 void lh_free(LHASH *lh);
\r
176 void *lh_insert(LHASH *lh, void *data);
\r
177 void *lh_delete(LHASH *lh, const void *data);
\r
178 void *lh_retrieve(LHASH *lh, const void *data);
\r
179 void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
\r
180 void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
\r
181 unsigned long lh_strhash(const char *c);
\r
182 unsigned long lh_num_items(const LHASH *lh);
\r
184 #ifndef OPENSSL_NO_FP_API
\r
185 void lh_stats(const LHASH *lh, FILE *out);
\r
186 void lh_node_stats(const LHASH *lh, FILE *out);
\r
187 void lh_node_usage_stats(const LHASH *lh, FILE *out);
\r
190 #ifndef OPENSSL_NO_BIO
\r
191 void lh_stats_bio(const LHASH *lh, BIO *out);
\r
192 void lh_node_stats_bio(const LHASH *lh, BIO *out);
\r
193 void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
\r