00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SFXHASH_
00014 #define _SFXHASH_
00015
00016 #include <stdlib.h>
00017 #include <string.h>
00018 #include <time.h>
00019
00020 #include "sfmemcap.h"
00021 #include "sfhashfcn.h"
00022
00023
00024
00025 #define SFXHASH_NOMEM -2
00026 #define SFXHASH_ERR -1
00027 #define SFXHASH_OK 0
00028 #define SFXHASH_INTABLE 1
00029
00030
00031
00032
00033 typedef struct _sfxhash_node
00034 {
00035 struct _sfxhash_node * gnext, * gprev;
00036 struct _sfxhash_node * next, * prev;
00037
00038 int rindex;
00039
00040 void * key;
00041 void * data;
00042
00043 } SFXHASH_NODE;
00044
00045
00046
00047
00048 typedef struct _sfxhash
00049 {
00050 SFHASHFCN * sfhashfcn;
00051 int keysize;
00052 int datasize;
00053 SFXHASH_NODE ** table;
00054 unsigned nrows;
00055 unsigned count;
00056
00057 unsigned crow;
00058 SFXHASH_NODE * cnode;
00059 int splay;
00060
00061 MEMCAP mc;
00062 unsigned overhead_bytes;
00063 unsigned overhead_blocks;
00064 unsigned find_fail;
00065 unsigned find_success;
00066
00067 SFXHASH_NODE * ghead, * gtail;
00068
00069 SFXHASH_NODE * fhead, * ftail;
00070 int recycle_nodes;
00071 unsigned anr_tries;
00072 unsigned anr_count;
00073 int anr_flag;
00074
00075 int (*anrfree)( void * key, void * data );
00076 int (*usrfree)( void * key, void * data );
00077 } SFXHASH;
00078
00079
00080
00081
00082
00083 SFXHASH * sfxhash_new( int nrows, int keysize, int datasize, int memcap,
00084 int anr_flag,
00085 int (*anrfunc)(void *key, void * data),
00086 int (*usrfunc)(void *key, void * data),
00087 int recycle_flag );
00088
00089 void sfxhash_delete( SFXHASH * h );
00090
00091 int sfxhash_add ( SFXHASH * h, void * key, void * data );
00092 SFXHASH_NODE * sfxhash_get_node( SFXHASH * t, void * key );
00093 int sfxhash_remove( SFXHASH * h, void * key );
00094 unsigned sfxhash_count( SFXHASH * h );
00095 unsigned sfxhash_anr_count( SFXHASH * h );
00096
00097 void * sfxhash_mru( SFXHASH * t );
00098 void * sfxhash_lru( SFXHASH * t );
00099 SFXHASH_NODE * sfxhash_mru_node( SFXHASH * t );
00100 SFXHASH_NODE * sfxhash_lru_node( SFXHASH * t );
00101 void * sfxhash_find( SFXHASH * h, void * key );
00102 SFXHASH_NODE * sfxhash_find_node( SFXHASH * t, void * key);
00103
00104 SFXHASH_NODE * sfxhash_findfirst( SFXHASH * h );
00105 SFXHASH_NODE * sfxhash_findnext ( SFXHASH * h );
00106
00107 SFXHASH_NODE * sfxhash_ghead( SFXHASH * h );
00108 SFXHASH_NODE * sfxhash_gnext( SFXHASH_NODE * n );
00109 void sfxhash_gmovetofront( SFXHASH *t, SFXHASH_NODE * hnode );
00110
00111
00112 void sfxhash_splaymode( SFXHASH * h, int mode );
00113
00114 void * sfxhash_alloc( SFXHASH * t, unsigned nbytes );
00115 void sfxhash_free( SFXHASH * t, void * p );
00116 int sfxhash_free_node(SFXHASH *t, SFXHASH_NODE *node);
00117
00118 unsigned sfxhash_maxdepth( SFXHASH * t );
00119 unsigned sfxhash_overhead_bytes( SFXHASH * t );
00120 unsigned sfxhash_overhead_blocks( SFXHASH * t );
00121 unsigned sfxhash_find_success( SFXHASH * h );
00122 unsigned sfxhash_find_fail( SFXHASH * h );
00123 unsigned sfxhash_find_total( SFXHASH * h );
00124
00125
00126 int sfxhash_set_keyops( SFXHASH *h ,
00127 unsigned (*hash_fcn)( SFHASHFCN * p,
00128 unsigned char *d,
00129 int n),
00130 int (*keycmp_fcn)( const void *s1,
00131 const void *s2,
00132 size_t n));
00133
00134
00135 #endif
00136