Changeset 739d00a in mainline for uspace/lib/libc/generic/libadt/hash_table.c
- Timestamp:
- 2008-03-06T22:18:23Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3298ddc
- Parents:
- 7b6d98b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/libadt/hash_table.c
r7b6d98b r739d00a 1 1 /* 2 * Copyright (c) 200 6Jakub Jermar2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 47 47 /** Create chained hash table. 48 48 * 49 * @param h 50 * @param m Number of slots in the hash table.51 * @param max_keys 52 * @param op 53 * @return true on success49 * @param h Hash table structure. Will be initialized by this call. 50 * @param m Number of hash table buckets. 51 * @param max_keys Maximal number of keys needed to identify an item. 52 * @param op Hash table operations structure. 53 * @return True on success 54 54 */ 55 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, hash_table_operations_t *op) 55 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, 56 hash_table_operations_t *op) 56 57 { 57 58 hash_count_t i; … … 77 78 } 78 79 79 /** Insert item into hash table.80 /** Destroy a hash table instance. 80 81 * 81 * @param h Hash table. 82 * @param key Array of all keys necessary to compute hash index. 83 * @param item Item to be inserted into the hash table. 82 * @param h Hash table to be destroyed. 83 */ 84 void hash_table_destroy(hash_table_t *h) 85 { 86 assert(h); 87 assert(h->entry); 88 free(h->entry); 89 } 90 91 /** Insert item into a hash table. 92 * 93 * @param h Hash table. 94 * @param key Array of all keys necessary to compute hash index. 95 * @param item Item to be inserted into the hash table. 84 96 */ 85 97 void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item) … … 98 110 /** Search hash table for an item matching keys. 99 111 * 100 * @param h 101 * @param key 112 * @param h Hash table. 113 * @param key Array of all keys needed to compute hash index. 102 114 * 103 * @return 115 * @return Matching item on success, NULL if there is no such item. 104 116 */ 105 117 link_t *hash_table_find(hash_table_t *h, unsigned long key[]) … … 113 125 assert(chain < h->entries); 114 126 115 for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) { 127 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 128 cur = cur->next) { 116 129 if (h->op->compare(key, h->max_keys, cur)) { 117 130 /* … … 129 142 * For each removed item, h->remove_callback() is called. 130 143 * 131 * @param h Hash table. 132 * @param key Array of keys that will be compared against items of the hash table. 133 * @param keys Number of keys in the 'key' array. 144 * @param h Hash table. 145 * @param key Array of keys that will be compared against items of 146 * the hash table. 147 * @param keys Number of keys in the 'key' array. 134 148 */ 135 149 void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys) … … 138 152 link_t *cur; 139 153 140 assert(h && h->op && h->op->hash && h->op->compare && h->op->remove_callback); 154 assert(h && h->op && h->op->hash && h->op->compare && 155 h->op->remove_callback); 141 156 assert(keys <= h->max_keys); 142 157 … … 144 159 145 160 /* 146 * All keys are known, hash_table_find() can be used to find the entry. 161 * All keys are known, hash_table_find() can be used to find the 162 * entry. 147 163 */ 148 164 … … 160 176 */ 161 177 for (chain = 0; chain < h->entries; chain++) { 162 for (cur = h->entry[chain].next; cur != &h->entry[chain]; cur = cur->next) { 178 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 179 cur = cur->next) { 163 180 if (h->op->compare(key, keys, cur)) { 164 181 link_t *hlp;
Note:
See TracChangeset
for help on using the changeset viewer.