Commit bd50f00ecce913aff0f929ead8a6c651d12ebd97

Added genhash_clear
genhash.c
(20 / 0)
  
241241 }
242242}
243243
244int
245genhash_clear(genhash_t *h)
246{
247 int i = 0, rv = 0;
248 assert(h != NULL);
249
250 for(i = 0; i < h->size; i++) {
251 while(h->buckets[i]) {
252 struct genhash_entry_t *p = NULL;
253 p = h->buckets[i];
254 h->buckets[i] = p->next;
255 h->ops.freeKey(p->key);
256 h->ops.freeValue(p->value);
257 free(p);
258 }
259 }
260
261 return rv;
262}
263
244264static void
245265count_entries(const void *key, const void *val, void *arg)
246266{
genhash.h
(9 / 0)
  
191191int genhash_size(genhash_t *h);
192192
193193/**
194 * Remove all items from a genhash.
195 *
196 * @param h the genhash
197 *
198 * @return the number of items removed
199 */
200int genhash_clear(genhash_t *h);
201
202/**
194203 * Get the total number of entries in this hash table that map to the given
195204 * key.
196205 *
  
1313struct _genhash {
1414 size_t size;
1515 struct hash_ops ops;
16 struct genhash_entry_t *buckets[0];
16 struct genhash_entry_t *buckets[];
1717};
  
232232 assert(h == NULL);
233233}
234234
235static void
236test_clear()
237{
238 genhash_t* h=get_test_hash();
239 assert(genhash_size(h) == 26);
240 genhash_clear(h);
241 assert(genhash_size(h) == 0);
242 genhash_free(h);
243}
244
235245int main(int argc, char **argv)
236246{
237247 test_construct();
251251 test_function_update();
252252 test_free_null();
253253 test_negative_size();
254 test_clear();
254255 return 0;
255256}