Changeset 1117 for 1.8.3/trunk/hdrs/htab.h
- Timestamp:
- 10/05/07 15:36:32 (1 year ago)
- Files:
-
- 1.8.3/trunk/hdrs/htab.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/trunk/hdrs/htab.h
r1032 r1117 4 4 #define __HTAB_H 5 5 6 typedef struct hashtable HASHTAB; 6 7 7 #define HTAB_UPSCALE 3.25 8 #define HTAB_DOWNSCALE 2.0 9 10 typedef struct hashentry HASHENT; 11 /** A hash table entry. 12 */ 13 struct hashentry { 14 struct hashentry *next; /**< Pointer to next entry */ 15 void *data; /**< Data for this entry */ 16 char *key; /**< Key for this entry */ 8 /** Hash table bucket struct */ 9 struct hash_bucket { 10 const char *key; 11 void *data; 17 12 }; 18 13 19 #define HASHENT_SIZE (sizeof(HASHENT))20 21 typedef struct hashtable HASHTAB;22 14 /** A hash table. 23 15 */ 24 16 struct hashtable { 25 int hashsize; /**< Size of hash table */ 26 int mask; /**< Mask for entries in table */ 17 int hashsize; /**< Size of buckets array */ 27 18 int entries; /**< Number of entries stored */ 28 HASHENT **buckets; /**< Pointer to pointer to entries */ 29 int last_hval; /**< State for hashfirst & hashnext. */ 30 HASHENT *last_entry; /**< State for hashfirst & hashnext. */ 31 int entry_size; /**< Size of each entry */ 19 int hashfunc_offset; /**< Which pair of hash functions to use */ 20 struct hash_bucket *buckets; /**< Buckets */ 21 int last_index; /**< State for hashfirst & hashnext. */ 32 22 void (*free_data) (void *); /**< Function to call on data when deleting 33 23 a entry. */ 34 24 }; 35 25 36 #define get_hashmask(x) hash_getmask(x) 37 #define hashinit(x,y, z) hash_init(x,y, z, NULL) 26 typedef struct hash_bucket HASHENT; 27 28 #define hashinit(tab, size) hash_init((tab), (size), NULL) 38 29 #define hashfind(key,tab) hash_value(hash_find(tab,key)) 39 #define hashadd(key,data,tab) hash_add(tab,key,data, 0) 40 #define hashadds(key, data, tab, size) hash_add(tab, key, data, size) 30 #define hashadd(key,data,tab) hash_add(tab,key,data) 41 31 #define hashdelete(key,tab) hash_delete(tab,hash_find(tab,key)) 42 32 #define hashflush(tab, size) hash_flush(tab,size) 43 33 #define hashfree(tab) hash_flush(tab, 0) 44 extern int hash_getmask(int *size); 45 extern void hash_init(HASHTAB *htab, int size, int data_size, void (*)(void *)); 46 extern HASHENT *hash_find(HASHTAB *htab, const char *key); 47 extern void *hash_value(HASHENT *entry); 48 extern char *hash_key(HASHENT *entry); 49 extern void hash_resize(HASHTAB *htab, int size); 50 extern int hash_add 51 (HASHTAB *htab, const char *key, void *hashdata, int extra_size); 52 extern void hash_delete(HASHTAB *htab, HASHENT *entry); 53 extern void hash_flush(HASHTAB *htab, int size); 54 extern void *hash_firstentry(HASHTAB *htab); 55 extern void *hash_nextentry(HASHTAB *htab); 56 extern char *hash_firstentry_key(HASHTAB *htab); 57 extern char *hash_nextentry_key(HASHTAB *htab); 58 extern void hash_stats_header(dbref player); 59 extern void hash_stats(dbref player, HASHTAB *htab, const char *hashname); 34 int hash_getmask(int *size); 35 void hash_init(HASHTAB *htab, int size, void (*)(void *)); 36 HASHENT *hash_find(HASHTAB *htab, const char *key); 37 #define hash_value(entry) (entry) ? (entry)->data : NULL 38 #define hash_key(entry) (entry) ? (entry)->key : NULL 39 bool hash_resize(HASHTAB *htab, int size); 40 bool hash_add(HASHTAB *htab, const char *key, void *hashdata); 41 void hash_delete(HASHTAB *htab, HASHENT *entry); 42 void hash_flush(HASHTAB *htab, int size); 43 void *hash_firstentry(HASHTAB *htab); 44 void *hash_nextentry(HASHTAB *htab); 45 const char *hash_firstentry_key(HASHTAB *htab); 46 const char *hash_nextentry_key(HASHTAB *htab); 47 void hash_stats_header(dbref player); 48 void hash_stats(dbref player, HASHTAB *htab, const char *hashname); 60 49 #endif
