Commit bd50f00ecce913aff0f929ead8a6c651d12ebd97
- Diff rendering mode:
- inline
- side by side
genhash.c
(20 / 0)
|   | |||
| 241 | 241 | } | |
| 242 | 242 | } | |
| 243 | 243 | ||
| 244 | int | ||
| 245 | genhash_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 | |||
| 244 | 264 | static void | |
| 245 | 265 | count_entries(const void *key, const void *val, void *arg) | |
| 246 | 266 | { |
genhash.h
(9 / 0)
|   | |||
| 191 | 191 | int genhash_size(genhash_t *h); | |
| 192 | 192 | ||
| 193 | 193 | /** | |
| 194 | * Remove all items from a genhash. | ||
| 195 | * | ||
| 196 | * @param h the genhash | ||
| 197 | * | ||
| 198 | * @return the number of items removed | ||
| 199 | */ | ||
| 200 | int genhash_clear(genhash_t *h); | ||
| 201 | |||
| 202 | /** | ||
| 194 | 203 | * Get the total number of entries in this hash table that map to the given | |
| 195 | 204 | * key. | |
| 196 | 205 | * |
genhash_int.h
(1 / 1)
|   | |||
| 13 | 13 | struct _genhash { | |
| 14 | 14 | size_t size; | |
| 15 | 15 | struct hash_ops ops; | |
| 16 | struct genhash_entry_t *buckets[0]; | ||
| 16 | struct genhash_entry_t *buckets[]; | ||
| 17 | 17 | }; |
test/hashtest.c
(11 / 0)
|   | |||
| 232 | 232 | assert(h == NULL); | |
| 233 | 233 | } | |
| 234 | 234 | ||
| 235 | static void | ||
| 236 | test_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 | |||
| 235 | 245 | int main(int argc, char **argv) | |
| 236 | 246 | { | |
| 237 | 247 | test_construct(); | |
| … | … | ||
| 251 | 251 | test_function_update(); | |
| 252 | 252 | test_free_null(); | |
| 253 | 253 | test_negative_size(); | |
| 254 | test_clear(); | ||
| 254 | 255 | return 0; | |
| 255 | 256 | } |

