Main Page | Class List | File List | Class Members | File Members

ght_hash_table.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  * Copyright (C) 2001, 2003-2004-2002,  Simon Kagstrom
00003  *
00004  * Filename:      ght_hash_table.h.in
00005  * Description:   The definitions used in the hash table.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020  * 02111-1307, USA.
00021  *
00022  * $Id: ght_hash_table.h.in,v 1.2 2003/03/22 14:41:42 ska Exp $
00023  *
00024  ********************************************************************/
00025 
00059 #ifndef GHT_HASH_TABLE_H
00060 #define GHT_HASH_TABLE_H
00061 
00062 #include <stdlib.h>                    /* size_t */
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  * The structure for hash entries.
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  * The structure used in iterations. You should not care about the
00108  * contents of this, it will be filled and updated by ght_first() and
00109   * ght_next().
00110  */
00111 typedef struct
00112 {
00113   int i_curr_bucket;         /* The current bucket */
00114   ght_hash_entry_t *p_entry; /* The current entry */
00115   ght_hash_entry_t *p_next;  /* The next entry */
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   /* private: */
00169   ght_hash_entry_t **pp_entries;
00170   int *p_nr;                         /* The number of entries in each bucket */
00171   int i_size_mask;                   /* The number of bits used in the size */
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 /* exported hash functions */
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 /* GHT_HASH_TABLE_H */

Generated on Sun Feb 29 10:49:35 2004 for libghthash by doxygen 1.3.5