aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-06-23 11:32:47 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-06-23 11:32:47 +0200
commitbd8f280af2db0663f15ced2e95cb26a07a1560c4 (patch)
treee9ad828e5342512c9d9da6de7219261ba483fb24
parent0563839f892db0225463263d083b7f18fa122af0 (diff)
downloaddns-bd8f280af2db0663f15ced2e95cb26a07a1560c4.tar.gz
minor fixes, twekas in test & tree
-rw-r--r--src/test.c4
-rw-r--r--src/tree.h8
2 files changed, 9 insertions, 3 deletions
diff --git a/src/test.c b/src/test.c
index f88aa3a..41dd197 100644
--- a/src/test.c
+++ b/src/test.c
@@ -54,8 +54,8 @@ int test_tree ()
printf("%s\n", tree_get(&root, "aa"));
for ( int i = 0; i < len; i++ ) {
- if ( ! tree_get(&root, keys[i]) )
- LOGPRINTF(_LOG_WARNING, "%s not found in tree", keys[i]);
+ if ( strcmp( tree_get(&root, keys[i]), data[i] ) )
+ LOGPRINTF(_LOG_WARNING, "Data does not match for %s", keys[i]);
}
printf("After Get\n");
diff --git a/src/tree.h b/src/tree.h
index 55dfb8b..2b69301 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -10,6 +10,11 @@
*
* The char* _key is used as a primary key, the tree can
* carry any generic payload in void* _data.
+ * _key is case INsensitive.
+ *
+ * tree_balanced_insert tries to create an optimally balanced
+ * tree from the given dataset. Only works correctly on an empty
+ * tree.
*
* The root does not need special initialization.
*
@@ -39,6 +44,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
+#include <string.h>
//TODO remove
#include <stdio.h>
@@ -61,7 +67,7 @@ int tree_insert ( struct tree_node** _root, char* _key, void* _data );
* Inserts the given list into the tree, achieving optimal depth.
* Expects a sorted list.
* */
-int tree_balanced_insert( struct tree_node** _root, void* _data[], char* _key[], unsigned int _len);
+int tree_balanced_insert ( struct tree_node** _root, void* _data[], char* _key[], unsigned int _len);
/**
* Returns (void*)node->data on success, NULL on failure