diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-04 11:25:37 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2019-02-05 18:06:13 +0100 |
commit | dc8474d9034d9281463bb69f7f7a922e3ea713ee (patch) | |
tree | c3b870ada88f7aaa48918c4eb8b5d865f2f82019 /trie.inc.h | |
parent | Work on propper memmory management for linked lists. (diff) | |
download | calp-dc8474d9034d9281463bb69f7f7a922e3ea713ee.tar.gz calp-dc8474d9034d9281463bb69f7f7a922e3ea713ee.tar.xz |
Normalize and improve INIT & FREE macros.
Diffstat (limited to '')
-rw-r--r-- | trie.inc.h | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -4,13 +4,13 @@ #include "err.h" -int CONSTRUCTOR_DECL ( TRIE(TYPE) ) { +INIT_F ( TRIE(TYPE) ) { NEW(TRIE_NODE(TYPE), t, '\0'); this->root = t; return 0; } -int CONSTRUCTOR_DECL (TRIE_NODE(TYPE), char c) { +INIT_F (TRIE_NODE(TYPE), char c) { this->c = c; this->value = NULL; this->next = NULL; @@ -18,7 +18,7 @@ int CONSTRUCTOR_DECL (TRIE_NODE(TYPE), char c) { return 0; } -int CONSTRUCTOR_DECL (TRIE_NODE(TYPE), +INIT_F (TRIE_NODE(TYPE), char c, TRIE_NODE(TYPE)* next, TRIE_NODE(TYPE)* child ) @@ -99,21 +99,21 @@ TYPE* TRIE_GET(TYPE) ( TRIE(TYPE)* trie, char* key ) { return 0; } -int TRIE_NODE_FREE(TYPE) ( TRIE_NODE(TYPE)* node ) { - if (node == NULL) return 0; - if (node->value != NULL) FFREE(TYPE, node->value); - if (node->next != NULL) TRIE_NODE_FREE(TYPE)(node->next); - if (node->child != NULL) TRIE_NODE_FREE(TYPE)(node->child); - free (node); +FREE_F(TRIE_NODE(TYPE)) { + if (this == NULL) return 0; + if (this->value != NULL) FFREE(TYPE, this->value); + if (this->next != NULL) FREE(TRIE_NODE(TYPE))(this->next); + if (this->child != NULL) FREE(TRIE_NODE(TYPE))(this->child); + free (this); return 0; } -int TRIE_FREE(TYPE) ( TRIE(TYPE)* trie ) { - if (trie->root->c != '\0') { +FREE_F(TRIE(TYPE)) { + if (this->root->c != '\0') { // ERR("Invalid trie"); return 1; } - return TRIE_NODE_FREE(TYPE)(trie->root); + return FREE(TRIE_NODE(TYPE))(this->root); } int TRIE_DOT(TYPE) ( TRIE(TYPE)* trie, FILE* f ) { |