diff options
author | David McMackins II <contact@mcmackins.org> | 2015-12-30 16:45:36 -0600 |
---|---|---|
committer | David McMackins II <contact@mcmackins.org> | 2015-12-30 16:45:36 -0600 |
commit | a3dc9fafd0f064d33d8b70a8292656232431cfab (patch) | |
tree | e9c1a85bce24651771325786ddea1fa0470c7033 | |
parent | 3e5ce525da57820b62c246599fe35e33fe63526f (diff) |
Add ability to free referenced data (stdlib free only)0.2.0
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | pfxtree.c | 11 | ||||
-rw-r--r-- | pfxtree.h | 15 | ||||
-rw-r--r-- | pfxtree.pc | 2 |
5 files changed, 26 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index 0c318b3..2c42d6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,7 @@ include_HEADERS = pfxtree.h lib_LTLIBRARIES = libpfxtree.la libpfxtree_la_SOURCES = pfxtree.c -libpfxtree_la_LDFLAGS = -version-info 1:0:1 +libpfxtree_la_LDFLAGS = -version-info 2:0:2 libpfxtree_la_CFLAGS = -Wall -Wextra -Wunreachable-code -ftrapv -std=c89 AM_CFLAGS = $(DEPS_CFLAGS) diff --git a/configure.ac b/configure.ac index 333178c..e4536a1 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ([2.60]) -AC_INIT([libpfxtree],[0.1.0],[support@delwink.com]) +AC_INIT([libpfxtree],[0.2.0],[support@delwink.com]) AC_CONFIG_SRCDIR([pfxtree.c]) AC_CONFIG_AUX_DIR([build-aux]) @@ -45,11 +45,20 @@ pt_new () void pt_free (PrefixTree *self) { + pt_deep_free (self, false); +} + +void +pt_deep_free (PrefixTree *self, bool free_data) +{ PrefixTree *child, *next = NULL; for (child = self->children; child != NULL; child = next) { + if (free_data && 'p' == child->type && child->data.p != NULL) + free (child->data.p); + next = child->next; - pt_free (child); + pt_deep_free (child, free_data); } free (self); @@ -17,8 +17,8 @@ /** * @file pfxtree.h - * @version 0.1 - * @date 10/04/2015 + * @version 0.2 + * @date 12/30/2015 * @author David McMackins II * @brief Delwink prefix tree (trie) library */ @@ -26,6 +26,8 @@ #ifndef DELWINK_PFXTREE_H #define DELWINK_PFXTREE_H +#include <stdbool.h> + #ifdef __cplusplus # define __BEGIN_DECLS extern "C" { # define __END_DECLS } @@ -78,6 +80,15 @@ void pt_free (PrefixTree *self); /** + * @brief Frees an allocated prefix tree (and its child nodes) and optionally + * its referenced data. + * @param self The tree to free. + * @param free_data Whether to free memory pointed to by the data (if pointer). + */ +void +pt_deep_free (PrefixTree *self, bool free_data); + +/** * @brief Adds a new word to a prefix tree with integer data. * @param self The tree to which to add the word. * @param word The word to be added. @@ -3,7 +3,7 @@ exec_prefix = ${prefix} libdir = ${exec_prefix}/lib includedir = ${prefix}/include -Version: 0.1.0 +Version: 0.2.0 Cflags = -I${includedir} Description: Delwink prefix tree library Name: pfxtree |