cn_map / cn_map_set_func_destructor
Syntax
void cn_map_set_func_destructor(CN_MAP map, void (*destruct_func)(CNM_NODE *))
Description
Sets the destructor function of
map to
destruct_func. The destruct function is an optional function that, if not NULL, is called when each node is freed from memory. This function is not intended to be used after data has been inserted into the CN_Map.
Return Value
N/A
Examples
Basic Usage
#include <stdio.h>
#include <stdlib.h>
#include "cn_cmp.h"
#include "cn_map.h"
//Frees the key c-string in a CN_Map node when it is removed from the CN_Map
void destruct_key(CNM_NODE *node) {
char *v = *(char **) node->key;
if (v != NULL)
free(v);
}
main() {
//Create a new cn_map
CN_MAP map = cn_map_init(char*, int, cn_cmp_cstr);
//Set the destructor function
cn_map_set_func_destructor(destruct_key);
//Free the CN_Map
cn_map_free(map);
}