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
00059 #ifndef GHT_HASH_TABLE_H
00060 #define GHT_HASH_TABLE_H
00061
00062 #include <stdlib.h>
00063
00064 #ifdef __cplusplus
00065 extern "C" {
00066 #endif
00067
00068 #define GHT_HEURISTICS_NONE 0
00069 #define GHT_HEURISTICS_TRANSPOSE 1
00070 #define GHT_HEURISTICS_MOVE_TO_FRONT 2
00071 #define GHT_AUTOMATIC_REHASH 4
00072
00073 #ifndef TRUE
00074 #define TRUE 1
00075 #endif
00076
00077 #ifndef FALSE
00078 #define FALSE 0
00079 #endif
00080
00082 typedef unsigned int ght_uint32_t;
00083
00088 typedef struct s_hash_key
00089 {
00090 unsigned int i_size;
00091 void *p_key;
00092 } ght_hash_key_t;
00093
00094
00095
00096
00097 typedef struct s_hash_entry
00098 {
00099 void *p_data;
00100
00101 struct s_hash_entry *p_next;
00102 struct s_hash_entry *p_prev;
00103 ght_hash_key_t key;
00104 } ght_hash_entry_t;
00105
00106
00107
00108
00109
00110
00111 typedef struct
00112 {
00113 int i_curr_bucket;
00114 ght_hash_entry_t *p_entry;
00115 ght_hash_entry_t *p_next;
00116 } ght_iterator_t;
00117
00131 typedef ght_uint32_t (*ght_fn_hash_t)(ght_hash_key_t *p_key);
00132
00144 typedef void *(*ght_fn_alloc_t)(size_t size);
00145
00152 typedef void (*ght_fn_free_t)(void *ptr);
00153
00154
00158 typedef struct
00159 {
00160 unsigned int i_items;
00161 unsigned int i_size;
00162 ght_fn_hash_t fn_hash;
00163 ght_fn_alloc_t fn_alloc;
00164 ght_fn_free_t fn_free;
00165 int i_heuristics;
00166 int i_automatic_rehash;
00168
00169 ght_hash_entry_t **pp_entries;
00170 int *p_nr;
00171 int i_size_mask;
00172 } ght_hash_table_t;
00173
00193 ght_hash_table_t *ght_create(unsigned int i_size);
00194
00216 void ght_set_alloc(ght_hash_table_t *p_ht, ght_fn_alloc_t fn_alloc, ght_fn_free_t fn_free);
00217
00228 void ght_set_hash(ght_hash_table_t *p_ht, ght_fn_hash_t fn_hash);
00229
00245 void ght_set_heuristics(ght_hash_table_t *p_ht, int i_heuristics);
00246
00261 void ght_set_rehash(ght_hash_table_t *p_ht, int b_rehash);
00262
00270 unsigned int ght_size(ght_hash_table_t *p_ht);
00271
00279 unsigned int ght_table_size(ght_hash_table_t *p_ht);
00280
00281
00315 int ght_insert(ght_hash_table_t *p_ht,
00316 void *p_entry_data,
00317 unsigned int i_key_size, void *p_key_data);
00318
00331 void *ght_replace(ght_hash_table_t *p_ht,
00332 void *p_entry_data,
00333 unsigned int i_key_size, void *p_key_data);
00334
00335
00346 void *ght_get(ght_hash_table_t *p_ht,
00347 unsigned int i_key_size, void *p_key_data);
00348
00359 void *ght_remove(ght_hash_table_t *p_ht,
00360 unsigned int i_key_size, void *p_key_data);
00361
00401 void *ght_first(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);
00402
00422 void *ght_next(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);
00423
00440 void ght_rehash(ght_hash_table_t *p_ht, unsigned int i_size);
00441
00464 void ght_finalize(ght_hash_table_t *p_ht);
00465
00466
00467
00480 ght_uint32_t ght_one_at_a_time_hash(ght_hash_key_t *p_key);
00481
00492 ght_uint32_t ght_rotating_hash(ght_hash_key_t *p_key);
00493
00504 ght_uint32_t ght_crc_hash(ght_hash_key_t *p_key);
00505
00506 #ifdef USE_PROFILING
00507
00511 void ght_print(ght_hash_table_t *p_ht);
00512 #endif
00513
00514 #ifdef __cplusplus
00515 }
00516 #endif
00517
00518 #endif