PennMUSH Community
Show
Ignore:
Timestamp:
10/05/07 15:36:32 (1 year ago)
Author:
shawnw
Message:

Merge with devel

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/trunk/hdrs/htab.h

    r1032 r1117  
    44#define __HTAB_H 
    55 
     6typedef struct hashtable HASHTAB; 
    67 
    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 */ 
     9struct hash_bucket { 
     10  const char *key; 
     11  void *data; 
    1712}; 
    1813 
    19 #define HASHENT_SIZE (sizeof(HASHENT)) 
    20  
    21 typedef struct hashtable HASHTAB; 
    2214/** A hash table. 
    2315 */ 
    2416struct hashtable { 
    25   int hashsize;                 /**< Size of hash table */ 
    26   int mask;                     /**< Mask for entries in table */ 
     17  int hashsize;                 /**< Size of buckets array */ 
    2718  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. */ 
    3222  void (*free_data) (void *);   /**< Function to call on data when deleting 
    3323                                   a entry. */ 
    3424}; 
    3525 
    36 #define get_hashmask(x) hash_getmask(x) 
    37 #define hashinit(x,y, z) hash_init(x,y, z, NULL) 
     26typedef struct hash_bucket HASHENT; 
     27 
     28#define hashinit(tab, size) hash_init((tab), (size), NULL) 
    3829#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) 
    4131#define hashdelete(key,tab) hash_delete(tab,hash_find(tab,key)) 
    4232#define hashflush(tab, size) hash_flush(tab,size) 
    4333#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); 
     34int hash_getmask(int *size); 
     35void hash_init(HASHTAB *htab, int size, void (*)(void *)); 
     36HASHENT *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 
     39bool hash_resize(HASHTAB *htab, int size); 
     40bool hash_add(HASHTAB *htab, const char *key, void *hashdata); 
     41void hash_delete(HASHTAB *htab, HASHENT *entry); 
     42void hash_flush(HASHTAB *htab, int size); 
     43void *hash_firstentry(HASHTAB *htab); 
     44void *hash_nextentry(HASHTAB *htab); 
     45const char *hash_firstentry_key(HASHTAB *htab); 
     46const char *hash_nextentry_key(HASHTAB *htab); 
     47void hash_stats_header(dbref player); 
     48void hash_stats(dbref player, HASHTAB *htab, const char *hashname); 
    6049#endif