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
00098
00099 typedef struct s_hash_entry
00100 {
00101 void *p_data;
00102
00103 struct s_hash_entry *p_next;
00104 struct s_hash_entry *p_prev;
00105 ght_hash_key_t key;
00106 } ght_hash_entry_t;
00107
00108
00109
00110
00111
00112
00113 typedef struct
00114 {
00115 int i_curr_bucket;
00116 ght_hash_entry_t *p_entry;
00117 ght_hash_entry_t *p_next;
00118 } ght_iterator_t;
00119
00133 typedef ght_uint32_t (*ght_fn_hash_t)(ght_hash_key_t *p_key);
00134
00145 typedef void *(*ght_fn_alloc_t)(size_t size);
00146
00153 typedef void (*ght_fn_free_t)(void *ptr);
00154
00158 typedef void (*ght_fn_bucket_free_callback_t)(void *data, void *key);
00159
00163 typedef struct
00164 {
00165 unsigned int i_items;
00166 unsigned int i_size;
00167 ght_fn_hash_t fn_hash;
00168 ght_fn_alloc_t fn_alloc;
00169 ght_fn_free_t fn_free;
00170 ght_fn_bucket_free_callback_t fn_bucket_free;
00171 int i_heuristics;
00172 int i_automatic_rehash;
00174
00175 ght_hash_entry_t **pp_entries;
00176 int *p_nr;
00177 int i_size_mask;
00178 unsigned int bucket_limit;
00179 } ght_hash_table_t;
00180
00200 ght_hash_table_t *ght_create(unsigned int i_size);
00201
00223 void ght_set_alloc(ght_hash_table_t *p_ht, ght_fn_alloc_t fn_alloc, ght_fn_free_t fn_free);
00224
00235 void ght_set_hash(ght_hash_table_t *p_ht, ght_fn_hash_t fn_hash);
00236
00252 void ght_set_heuristics(ght_hash_table_t *p_ht, int i_heuristics);
00253
00268 void ght_set_rehash(ght_hash_table_t *p_ht, int b_rehash);
00269
00290 void ght_set_bounded_buckets(ght_hash_table_t *p_ht, unsigned int limit, ght_fn_bucket_free_callback_t fn);
00291
00292
00300 unsigned int ght_size(ght_hash_table_t *p_ht);
00301
00309 unsigned int ght_table_size(ght_hash_table_t *p_ht);
00310
00311
00346 int ght_insert(ght_hash_table_t *p_ht,
00347 void *p_entry_data,
00348 unsigned int i_key_size, void *p_key_data);
00349
00362 void *ght_replace(ght_hash_table_t *p_ht,
00363 void *p_entry_data,
00364 unsigned int i_key_size, void *p_key_data);
00365
00366
00377 void *ght_get(ght_hash_table_t *p_ht,
00378 unsigned int i_key_size, void *p_key_data);
00379
00390 void *ght_remove(ght_hash_table_t *p_ht,
00391 unsigned int i_key_size, void *p_key_data);
00392
00434 void *ght_first(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);
00435
00455 void *ght_next(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, void **pp_key);
00456
00473 void ght_rehash(ght_hash_table_t *p_ht, unsigned int i_size);
00474
00497 void ght_finalize(ght_hash_table_t *p_ht);
00498
00499
00500
00513 ght_uint32_t ght_one_at_a_time_hash(ght_hash_key_t *p_key);
00514
00525 ght_uint32_t ght_rotating_hash(ght_hash_key_t *p_key);
00526
00537 ght_uint32_t ght_crc_hash(ght_hash_key_t *p_key);
00538
00539 #ifdef USE_PROFILING
00540
00544 void ght_print(ght_hash_table_t *p_ht);
00545 #endif
00546
00547 #ifdef __cplusplus
00548 }
00549 #endif
00550
00551 #endif