Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

epHash.h

Go to the documentation of this file.
00001 
00011 #ifndef _EPHASH_H_
00012 #define _EPHASH_H_
00013 
00014 #include "epDefs.h"
00015 
00017 struct epHashElt_s {
00018   void *key,                
00019        *value;              
00020   struct epHashElt_s *next; 
00021 };
00022 
00024 typedef struct epHash_s {
00025   struct epHashElt_s **bucketArray; 
00026   long numOfBuckets,                
00027        numOfElements;               
00029   double lowerRehashThreshold,    
00030          upperRehashThreshold,    
00031          idealRatio;              
00035   boolean_t (*keyComparisonFunction)(const void *key1, const void *key2);
00036   //boolean (*valueCompare)(const void *value1, const void *value2);
00037 
00038   /* hashkey function                                                        */
00039   uint (*hashFunction)(const void *key);
00040   /* key deallocator function                                                */
00041   int  (*keyDeallocatorFunction)(void *key);
00042   /* value deallocator function                                              */
00043   int  (*valueDeallocatorFunction)(void *value);
00044 } epHash_t;
00045 
00046 
00047 #define HAS_TO_BE_REHASHED(hTable)                                 \
00048          ((  (hTable)->upperRehashThreshold > 0.0 &&               \
00049            (((hTable)->numOfElements / (hTable)->numOfBuckets) >   \
00050              (hTable)->upperRehashThreshold))                      \
00051               ||                                                   \
00052           (  (hTable)->lowerRehashThreshold > 0.0 &&               \
00053            (((hTable)->numOfElements / (hTable)->numOfBuckets) <   \
00054              (hTable)->lowerRehashThreshold)))                     
00055 
00056 
00057 /* par défaut, par de rehash automatique décrémentiel */
00058 #define _DEFAULT_LowerRehashThreshold  0.0
00059 #define _DEFAULT_UpperRehashThreshold  15.0
00060 #define _DEFAULT_IdealRatio            3.0
00061 
00062 
00063 epHash_t *epHash_create(const ulong numOfBuckets,
00064   boolean_t (*keyComparisonFunction)(const void *key1, const void *key2),
00065   uint    (*hashFunction)(const void *key),
00066   int     (*keyDeallocatorFunction)(void *key),
00067   int     (*valueDeallocatorFunction)(void *value));
00068 
00069 int epHash_destroy(epHash_t *hashTable);
00070 uint epHash_size(epHash_t *hashTable);
00071 boolean_t epHash_isEmpty(epHash_t *hashTable);
00072 uint epHash_getNumOfBuckets(epHash_t *hashTable);
00073 int epHash_put(epHash_t *hashTable, const void *key, const void *value);
00074 void *epHash_get(const epHash_t *hashTable, const void *key);
00075 int epHash_remove(epHash_t *hashTable, const void *key);
00076 boolean_t epHash_containsKey(epHash_t *hashTable, const void *key);
00077 int epHash_rehash(epHash_t *hashTable, uint numOfBuckets);
00078 void epHash_setIdealRatio(epHash_t *hashTable, double idealRatio,
00079                           double lowerRehashThreshold, 
00080                           double upperRehashThreshold);
00081 uint calculateIdealNumOfBuckets(const epHash_t *hashTable);
00082 
00083 #endif /* _EPHASH_H_ */
00084 
00085 
00086 
00087 
00088 
00089 

Generated at Sun Nov 25 14:05:07 2001 for ExtendedPersonnalLibrary by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000