96
* }
97
*
98
* if (!strcmp("end", action)) {
99
- * hashmap_free_entries(&map, struct long2string, ent);
99
+ * hashmap_clear_and_free(&map, struct long2string, ent);
100
* break;
101
* }
102
* }
237
238
/* internal functions for clearing or freeing hashmap */
239
void hashmap_partial_clear_(struct hashmap *map, ssize_t offset);
240
-void hashmap_free_(struct hashmap *map, ssize_t offset);
240
+void hashmap_clear_(struct hashmap *map, ssize_t offset);
241
242
/*
243
* Frees a hashmap structure and allocated memory for the table, but does not
253
* free(e->somefield);
254
* free(e);
255
* }
256
- * hashmap_free(map);
256
+ * hashmap_clear(map);
257
*
258
* instead of
259
*
260
* hashmap_for_each_entry(map, hashmap_iter, e, hashmap_entry_name) {
261
* free(e->somefield);
262
* }
263
- * hashmap_free_entries(map, struct my_entry_struct, hashmap_entry_name);
263
+ * hashmap_clear_and_free(map, struct my_entry_struct, hashmap_entry_name);
264
*
265
* to avoid the implicit extra loop over the entries. However, if there are
266
* no special fields in your entry that need to be freed beyond the entry
267
* itself, it is probably simpler to avoid the explicit loop and just call
268
- * hashmap_free_entries().
268
+ * hashmap_clear_and_free().
269
*/
270
-#define hashmap_free(map) hashmap_free_(map, -1)
270
+#define hashmap_clear(map) hashmap_clear_(map, -1)
271
272
/*
273
- * Basically the same as calling hashmap_free() followed by hashmap_init(),
274
- * but doesn't incur the overhead of deallocating and reallocating
275
- * map->table; it leaves map->table allocated and the same size but zeroes
276
- * it out so it's ready for use again as an empty map. As with
277
- * hashmap_free(), you may need to free the entries yourself before calling
278
- * this function.
273
+ * Similar to hashmap_clear(), except that the table is no deallocated; it
274
+ * is merely zeroed out but left the same size as before. If the hashmap
275
+ * will be reused, this avoids the overhead of deallocating and
276
+ * reallocating map->table. As with hashmap_clear(), you may need to free
277
+ * the entries yourself before calling this function.
278
*/
279
#define hashmap_partial_clear(map) hashmap_partial_clear_(map, -1)
280
281
/*
283
- * Frees @map and all entries. @type is the struct type of the entry
284
- * where @member is the hashmap_entry struct used to associate with @map.
282
+ * Similar to hashmap_clear() but also frees all entries. @type is the
283
+ * struct type of the entry where @member is the hashmap_entry struct used
284
+ * to associate with @map.
285
*
286
- * See usage note above hashmap_free().
286
+ * See usage note above hashmap_clear().
287
*/
288
-#define hashmap_free_entries(map, type, member) \
289
- hashmap_free_(map, offsetof(type, member));
288
+#define hashmap_clear_and_free(map, type, member) \
289
+ hashmap_clear_(map, offsetof(type, member))
290
+
291
+/*
292
+ * Similar to hashmap_partial_clear() but also frees all entries. @type is
293
+ * the struct type of the entry where @member is the hashmap_entry struct
294
+ * used to associate with @map.
295
+ *
296
+ * See usage note above hashmap_clear().
297
+ */
298
+#define hashmap_partial_clear_and_free(map, type, member) \
299
+ hashmap_partial_clear_(map, offsetof(type, member))
300
301
/* hashmap_entry functions */
302