- Timestamp:
- 05/07/06 07:24:49 (6 years ago)
- Location:
- branches/ithildin-1.1
- Files:
-
- 2 edited
-
include/ithildin/hash.h (modified) (3 diffs)
-
source/hash.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ithildin-1.1/include/ithildin/hash.h
r724 r726 22 22 23 23 struct hashtable { 24 int size;/* thte size of the hash table */24 uint32_t size; /* thte size of the hash table */ 25 25 #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 */ 27 27 #define hashtable_count(x) ((x)->entries) 28 28 struct hashbucket *table; /* our table */ … … 35 35 /* these are useful for debugging the state of the hash system */ 36 36 #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 */ 39 39 #endif 40 40 #define HASH_FL_NOCASE 0x1 /* ignore case (tolower before hash) */ … … 55 55 56 56 /* table management functions */ 57 hashtable_t *create_hash_table( int, size_t, size_t, int, const char *);57 hashtable_t *create_hash_table(uint32_t, size_t, size_t, int, const char *); 58 58 void destroy_hash_table(hashtable_t *); 59 void resize_hash_table(hashtable_t *table, int elems);60 59 int hash_insert(hashtable_t *, void *); 61 60 int hash_delete(hashtable_t *, void *); -
branches/ithildin-1.1/source/hash.c
r724 r726 13 13 14 14 IDSTRING(rcsid, "$Id$"); 15 16 static void resize_hash_table(hashtable_t *table, uint32_t elems); 17 static unsigned int hash_get_key_hash(hashtable_t *, void *, size_t); 15 18 16 19 /* … … 30 33 * out much in terms of speed. 31 34 */ 32 hashtable_t *create_hash_table( int elems, size_t offset, size_t len,35 hashtable_t *create_hash_table(uint32_t elems, size_t offset, size_t len, 33 36 int flags, const char *cmpname) { 34 37 hashtable_t *htp = malloc(sizeof(hashtable_t)); 35 u _int32_t real_elems = 0x80;38 uint32_t real_elems = 0x80; 36 39 37 40 /* Take elems and begin shifting real_elems to the left until it is … … 50 53 if (real_elems > elems) 51 54 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); 52 59 53 60 htp->size = real_elems; … … 57 64 #ifdef DEBUG_CODE 58 65 htp->max_per_bucket = 1; 59 htp->empty_buckets = elems;66 htp->empty_buckets = real_elems; 60 67 #endif 61 68 htp->flags = flags; … … 92 99 * efficient, however if used judiciously it should enhance performance, not 93 100 * hinder it. 'elems' is the new size of the table. */ 94 void resize_hash_table(hashtable_t *table, int elems) {101 static void resize_hash_table(hashtable_t *table, uint32_t elems) { 95 102 struct hashbucket *oldtable; 96 103 int oldsize, i; … … 121 128 free(oldtable); 122 129 } 123 124 static unsigned int hash_get_key_hash(hashtable_t *, void *, size_t);125 130 126 131 /*
Note: See TracChangeset
for help on using the changeset viewer.
