aboutsummaryrefslogtreecommitdiff
path: root/src/tree.c
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-03-16 16:59:36 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-03-16 16:59:36 +0100
commitc36c7fedf969fa49e832c7d2739ea4d1ad1108f2 (patch)
tree637a346344e1bc025ad82785cf0cc73011881fd9 /src/tree.c
parent47334cfaa2315828e6f7b959a1bde180c9c29604 (diff)
downloaddns-c36c7fedf969fa49e832c7d2739ea4d1ad1108f2.tar.gz
updated tree to be generic
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/tree.c b/src/tree.c
index c6fc33b..899514e 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -37,9 +37,27 @@ int tree_balance ( struct tree_node** _root )
return 1;
}
-int tree_destroy ( struct tree_node** _root )
+int tree_destroy ( struct tree_node** _root, uint8_t _options )
{
- return 1;
+ while(*_root)
+ {
+ struct tree_node** node = _root;
+
+ while( (*node)->above || (*node)->below )
+ node= (*node)->above ? & (*node)->above : & (*node)->below ;
+
+ printf( "%s\n", (*node)->data );
+
+ if (_options & _TREE_FREE_KEY)
+ free( (*node)->data );
+ if (_options & _TREE_FREE_KEY)
+ free( (*node)->key );
+
+ free ( *node );
+ *node = NULL;
+ }
+
+ return 0;
}
int string_compare ( char* _1, char* _2 )
@@ -88,7 +106,7 @@ void* tree_get ( struct tree_node** _root, char* _query )
}
}
- return *node ? (*node)->key : NULL;
+ return *node ? (*node)->data : NULL;
return 0;
}