Changeset 726 for branches


Ignore:
Timestamp:
05/07/06 07:24:49 (6 years ago)
Author:
wd
Message:

Update/fix hash bugs.

Location:
branches/ithildin-1.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ithildin-1.1/include/ithildin/hash.h

    r724 r726  
    2222 
    2323struct hashtable { 
    24     int     size;           /* thte size of the hash table */ 
     24    uint32_t size;          /* thte size of the hash table */ 
    2525#define hashtable_size(x) ((x)->size) 
    26     int     entries;        /* number of entries in the hash table */ 
     26    uint32_t entries;       /* number of entries in the hash table */ 
    2727#define hashtable_count(x) ((x)->entries) 
    2828    struct hashbucket *table;   /* our table */ 
     
    3535    /* these are useful for debugging the state of the hash system */ 
    3636#ifdef DEBUG_CODE 
    37     int            max_per_bucket; /* most entries in a single bucket */ 
    38     int            empty_buckets;  /* number of empty buckets */ 
     37    int     max_per_bucket; /* most entries in a single bucket */ 
     38    uint32_t empty_buckets; /* number of empty buckets */ 
    3939#endif 
    4040#define HASH_FL_NOCASE 0x1      /* ignore case (tolower before hash) */ 
     
    5555 
    5656/* table management functions */ 
    57 hashtable_t *create_hash_table(int, size_t, size_t, int, const char *); 
     57hashtable_t *create_hash_table(uint32_t, size_t, size_t, int, const char *); 
    5858void destroy_hash_table(hashtable_t *); 
    59 void resize_hash_table(hashtable_t *table, int elems); 
    6059int hash_insert(hashtable_t *, void *); 
    6160int hash_delete(hashtable_t *, void *); 
  • branches/ithildin-1.1/source/hash.c

    r724 r726  
    1313 
    1414IDSTRING(rcsid, "$Id$"); 
     15 
     16static void resize_hash_table(hashtable_t *table, uint32_t elems); 
     17static unsigned int hash_get_key_hash(hashtable_t *, void *, size_t); 
    1518 
    1619/* 
     
    3033 * out much in terms of speed. 
    3134 */ 
    32 hashtable_t *create_hash_table(int elems, size_t offset, size_t len, 
     35hashtable_t *create_hash_table(uint32_t elems, size_t offset, size_t len, 
    3336        int flags, const char *cmpname) { 
    3437    hashtable_t *htp = malloc(sizeof(hashtable_t)); 
    35     u_int32_t real_elems = 0x80; 
     38    uint32_t real_elems = 0x80; 
    3639     
    3740    /* Take elems and begin shifting real_elems to the left until it is 
     
    5053    if (real_elems > elems) 
    5154        real_elems >>= 1; 
     55 
     56    if (real_elems != elems) 
     57        log_debug("Request for %d element hash table adjusted to %d " 
     58                "elements", elems, real_elems); 
    5259 
    5360    htp->size = real_elems; 
     
    5764#ifdef DEBUG_CODE 
    5865    htp->max_per_bucket = 1; 
    59     htp->empty_buckets = elems; 
     66    htp->empty_buckets = real_elems; 
    6067#endif 
    6168    htp->flags = flags; 
     
    9299 * efficient, however if used judiciously it should enhance performance, not 
    93100 * hinder it.  'elems' is the new size of the table. */ 
    94 void resize_hash_table(hashtable_t *table, int elems) { 
     101static void resize_hash_table(hashtable_t *table, uint32_t elems) { 
    95102    struct hashbucket *oldtable; 
    96103    int oldsize, i; 
     
    121128    free(oldtable); 
    122129} 
    123  
    124 static unsigned int hash_get_key_hash(hashtable_t *, void *, size_t); 
    125130 
    126131/* 
Note: See TracChangeset for help on using the changeset viewer.