Changeset 4f34b6a in mainline
- Timestamp:
- 2006-03-14T22:55:01Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 936351c1
- Parents:
- ee7736e
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libadt/Makefile
ree7736e r4f34b6a 42 42 43 43 GENERIC_SOURCES = \ 44 generic/list.c 44 generic/list.c \ 45 generic/hash_table.c 45 46 46 47 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) -
libadt/generic/hash_table.c
ree7736e r4f34b6a 36 36 #include <malloc.h> 37 37 #include <assert.h> 38 #include <stdio.h> 39 #include <string.h> 38 40 39 41 /** Create chained hash table. … … 43 45 * @param max_keys Maximal number of keys needed to identify an item. 44 46 * @param op Hash table operations structure. 47 * @return true on success 45 48 */ 46 voidhash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op)49 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op) 47 50 { 48 int i;51 hash_count_t i; 49 52 50 ASSERT(h);51 ASSERT(op && op->hash && op->compare);52 ASSERT(max_keys > 0);53 assert(h); 54 assert(op && op->hash && op->compare); 55 assert(max_keys > 0); 53 56 54 h->entry = malloc(m * sizeof(link_t *) , 0);57 h->entry = malloc(m * sizeof(link_t *)); 55 58 if (!h->entry) { 56 panic("cannot allocate memory for hash table\n"); 59 printf("cannot allocate memory for hash table\n"); 60 return false; 57 61 } 58 memset b((__address) h->entry, m * sizeof(link_t *), 0);62 memset((void *) h->entry, 0, m * sizeof(link_t *)); 59 63 60 64 for (i = 0; i < m; i++) … … 64 68 h->max_keys = max_keys; 65 69 h->op = op; 70 return true; 66 71 } 67 72 … … 72 77 * @param item Item to be inserted into the hash table. 73 78 */ 74 void hash_table_insert(hash_table_t *h, __nativekey[], link_t *item)79 void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item) 75 80 { 76 81 hash_index_t chain; 77 82 78 ASSERT(item);79 ASSERT(h && h->op && h->op->hash && h->op->compare);83 assert(item); 84 assert(h && h->op && h->op->hash && h->op->compare); 80 85 81 86 chain = h->op->hash(key); 82 ASSERT(chain < h->entries);87 assert(chain < h->entries); 83 88 84 89 list_append(item, &h->entry[chain]); … … 92 97 * @return Matching item on success, NULL if there is no such item. 93 98 */ 94 link_t *hash_table_find(hash_table_t *h, __nativekey[])99 link_t *hash_table_find(hash_table_t *h, unsigned long key[]) 95 100 { 96 101 link_t *cur; 97 102 hash_index_t chain; 98 103 99 ASSERT(h && h->op && h->op->hash && h->op->compare);104 assert(h && h->op && h->op->hash && h->op->compare); 100 105 101 106 chain = h->op->hash(key); 102 ASSERT(chain < h->entries);107 assert(chain < h->entries); 103 108 104 109 /* … … 126 131 * @param keys Number of keys in the 'key' array. 127 132 */ 128 void hash_table_remove(hash_table_t *h, __nativekey[], hash_count_t keys)133 void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys) 129 134 { 130 135 hash_index_t chain; 131 136 link_t *cur; 132 137 133 ASSERT(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback);134 ASSERT(keys <= h->max_keys);138 assert(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback); 139 assert(keys <= h->max_keys); 135 140 136 141 if (keys == h->max_keys) { -
libadt/include/hash_table.h
ree7736e r4f34b6a 54 54 * @return Index into hash table. 55 55 */ 56 hash_index_t (* hash)( intkey[]);56 hash_index_t (* hash)(unsigned long key[]); 57 57 58 58 /** Hash table item comparison function. … … 62 62 * @return true if the keys match, false otherwise. 63 63 */ 64 int (*compare)( intkey[], hash_count_t keys, link_t *item);64 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 65 65 66 66 /** Hash table item removal callback. … … 73 73 #define hash_table_get_instance(item, type, member) list_get_instance((item), type, member) 74 74 75 extern voidhash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op);76 extern void hash_table_insert(hash_table_t *h, intkey[], link_t *item);77 extern link_t *hash_table_find(hash_table_t *h, intkey[]);78 extern void hash_table_remove(hash_table_t *h, intkey[], hash_count_t keys);75 extern int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op); 76 extern void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item); 77 extern link_t *hash_table_find(hash_table_t *h, unsigned long key[]); 78 extern void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys); 79 79 80 80 #endif
Note:
See TracChangeset
for help on using the changeset viewer.