lhash.h

Go to the documentation of this file.
00001 /* crypto/lhash/lhash.h */
00002 /* Copyright (C) 1995-1998 Eric Young ([email protected])
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young ([email protected]).
00007  * The implementation was written so as to conform with Netscapes SSL.
00008  * 
00009  * This library is free for commercial and non-commercial use as long as
00010  * the following conditions are aheared to.  The following conditions
00011  * apply to all code found in this distribution, be it the RC4, RSA,
00012  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
00013  * included with this distribution is covered by the same copyright terms
00014  * except that the holder is Tim Hudson ([email protected]).
00015  * 
00016  * Copyright remains Eric Young's, and as such any Copyright notices in
00017  * the code are not to be removed.
00018  * If this package is used in a product, Eric Young should be given attribution
00019  * as the author of the parts of the library used.
00020  * This can be in the form of a textual message at program startup or
00021  * in documentation (online or textual) provided with the package.
00022  * 
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions
00025  * are met:
00026  * 1. Redistributions of source code must retain the copyright
00027  *    notice, this list of conditions and the following disclaimer.
00028  * 2. Redistributions in binary form must reproduce the above copyright
00029  *    notice, this list of conditions and the following disclaimer in the
00030  *    documentation and/or other materials provided with the distribution.
00031  * 3. All advertising materials mentioning features or use of this software
00032  *    must display the following acknowledgement:
00033  *    "This product includes cryptographic software written by
00034  *     Eric Young ([email protected])"
00035  *    The word 'cryptographic' can be left out if the rouines from the library
00036  *    being used are not cryptographic related :-).
00037  * 4. If you include any Windows specific code (or a derivative thereof) from 
00038  *    the apps directory (application code) you must include an acknowledgement:
00039  *    "This product includes software written by Tim Hudson ([email protected])"
00040  * 
00041  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
00042  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00044  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00045  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00046  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00047  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00049  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00050  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00051  * SUCH DAMAGE.
00052  * 
00053  * The licence and distribution terms for any publically available version or
00054  * derivative of this code cannot be changed.  i.e. this code cannot simply be
00055  * copied and put under another distribution licence
00056  * [including the GNU Public Licence.]
00057  */
00058 /*
00059  © Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00060  */
00061 
00062 /* Header for dynamic hash table routines
00063  * Author - Eric Young
00064  */
00065 
00066 #ifndef HEADER_LHASH_H
00067 #define HEADER_LHASH_H
00068 
00069 #if (defined(__SYMBIAN32__) && !defined(SYMBIAN))
00070 #define SYMBIAN
00071 #endif
00072 
00073 #ifdef SYMBIAN
00074 #include <e32def.h>
00075 #endif
00076 #include <openssl/e_os2.h>
00077 #ifndef OPENSSL_NO_FP_API
00078 #include <stdio.h>
00079 #endif
00080 
00081 #ifndef OPENSSL_NO_BIO
00082 #include <openssl/bio.h>
00083 #endif
00084 
00085 #ifdef  __cplusplus
00086 extern "C" {
00087 #endif
00088 
00089 typedef struct lhash_node_st
00090         {
00091         void *data;
00092         struct lhash_node_st *next;
00093 #ifndef OPENSSL_NO_HASH_COMP
00094         unsigned long hash;
00095 #endif
00096         } LHASH_NODE;
00097 
00098 typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
00099 typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
00100 typedef void (*LHASH_DOALL_FN_TYPE)(void *);
00101 typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
00102 
00103 /* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
00104  * This way, callbacks can be provided to LHASH structures without function
00105  * pointer casting and the macro-defined callbacks provide per-variable casting
00106  * before deferring to the underlying type-specific callbacks. NB: It is
00107  * possible to place a "static" in front of both the DECLARE and IMPLEMENT
00108  * macros if the functions are strictly internal. */
00109 
00110 /* First: "hash" functions */
00111 #define DECLARE_LHASH_HASH_FN(f_name,o_type) \
00112         unsigned long f_name##_LHASH_HASH(const void *);
00113 #define IMPLEMENT_LHASH_HASH_FN(f_name,o_type) \
00114         unsigned long f_name##_LHASH_HASH(const void *arg) { \
00115                 o_type a = (o_type)arg; \
00116                 return f_name(a); }
00117 #define LHASH_HASH_FN(f_name) f_name##_LHASH_HASH
00118 
00119 /* Second: "compare" functions */
00120 #define DECLARE_LHASH_COMP_FN(f_name,o_type) \
00121         int f_name##_LHASH_COMP(const void *, const void *);
00122 #define IMPLEMENT_LHASH_COMP_FN(f_name,o_type) \
00123         int f_name##_LHASH_COMP(const void *arg1, const void *arg2) { \
00124                 o_type a = (o_type)arg1; \
00125                 o_type b = (o_type)arg2; \
00126                 return f_name(a,b); }
00127 #define LHASH_COMP_FN(f_name) f_name##_LHASH_COMP
00128 
00129 /* Third: "doall" functions */
00130 #define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
00131          void f_name##_LHASH_DOALL(void *);
00132 #define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
00133          void f_name##_LHASH_DOALL(void *arg) { \
00134                 o_type a = (o_type)arg; \
00135                 f_name(a); }
00136 #define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
00137 
00138 /* Fourth: "doall_arg" functions */
00139 #define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
00140         void f_name##_LHASH_DOALL_ARG(void *, void *);
00141 #define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
00142         void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \
00143                 o_type a = (o_type)arg1; \
00144                 a_type b = (a_type)arg2; \
00145                 f_name(a,b); }
00146 #define LHASH_DOALL_ARG_FN(f_name) f_name##_LHASH_DOALL_ARG
00147 
00148 typedef struct lhash_st
00149         {
00150         LHASH_NODE **b;
00151         LHASH_COMP_FN_TYPE comp;
00152         LHASH_HASH_FN_TYPE hash;
00153         unsigned int num_nodes;
00154         unsigned int num_alloc_nodes;
00155         unsigned int p;
00156         unsigned int pmax;
00157         unsigned long up_load; /* load times 256 */
00158         unsigned long down_load; /* load times 256 */
00159         unsigned long num_items;
00160 
00161         unsigned long num_expands;
00162         unsigned long num_expand_reallocs;
00163         unsigned long num_contracts;
00164         unsigned long num_contract_reallocs;
00165         unsigned long num_hash_calls;
00166         unsigned long num_comp_calls;
00167         unsigned long num_insert;
00168         unsigned long num_replace;
00169         unsigned long num_delete;
00170         unsigned long num_no_delete;
00171         unsigned long num_retrieve;
00172         unsigned long num_retrieve_miss;
00173         unsigned long num_hash_comps;
00174 
00175         int error;
00176         } LHASH;
00177 
00178 #define LH_LOAD_MULT    256
00179 
00180 /* Indicates a malloc() error in the last call, this is only bad
00181  * in lh_insert(). */
00182 #define lh_error(lh)    ((lh)->error)
00183 
00184 IMPORT_C LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
00185 IMPORT_C void lh_free(LHASH *lh);
00186 IMPORT_C void *lh_insert(LHASH *lh, void *data);
00187 IMPORT_C void *lh_delete(LHASH *lh, const void *data);
00188 IMPORT_C void *lh_retrieve(LHASH *lh, const void *data);
00189 IMPORT_C void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
00190 IMPORT_C void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg);
00191 IMPORT_C unsigned long lh_strhash(const char *c);
00192 IMPORT_C unsigned long lh_num_items(const LHASH *lh);
00193 
00194 #ifndef OPENSSL_NO_FP_API
00195 IMPORT_C void lh_stats(const LHASH *lh, FILE *out);
00196 IMPORT_C void lh_node_stats(const LHASH *lh, FILE *out);
00197 IMPORT_C void lh_node_usage_stats(const LHASH *lh, FILE *out);
00198 #endif
00199 
00200 #ifndef OPENSSL_NO_BIO
00201 IMPORT_C void lh_stats_bio(const LHASH *lh, BIO *out);
00202 IMPORT_C void lh_node_stats_bio(const LHASH *lh, BIO *out);
00203 IMPORT_C void lh_node_usage_stats_bio(const LHASH *lh, BIO *out);
00204 #endif
00205 #ifdef  __cplusplus
00206 }
00207 #endif
00208 
00209 #endif
00210 

Copyright © Nokia Corporation 2001-2008
Back to top