PennMUSH Community

root/1.8.3/trunk/hdrs/htab.h

Revision 1117, 1.8 kB (checked in by shawnw, 11 months ago)

Merge with devel

Line 
1 /* htab.h - Structures and declarations needed for table hashing */
2
3 #ifndef __HTAB_H
4 #define __HTAB_H
5
6 typedef struct hashtable HASHTAB;
7
8 /** Hash table bucket struct */
9 struct hash_bucket {
10   const char *key;
11   void *data;
12 };
13
14 /** A hash table.
15  */
16 struct hashtable {
17   int hashsize;                 /**< Size of buckets array */
18   int entries;                  /**< Number of entries stored */
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. */
22   void (*free_data) (void *);   /**< Function to call on data when deleting
23                                    a entry. */
24 };
25
26 typedef struct hash_bucket HASHENT;
27
28 #define hashinit(tab, size) hash_init((tab), (size), NULL)
29 #define hashfind(key,tab) hash_value(hash_find(tab,key))
30 #define hashadd(key,data,tab) hash_add(tab,key,data)
31 #define hashdelete(key,tab) hash_delete(tab,hash_find(tab,key))
32 #define hashflush(tab, size) hash_flush(tab,size)
33 #define hashfree(tab) hash_flush(tab, 0)
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);
49 #endif
50
Note: See TracBrowser for help on using the browser.