diff tern.h @ 1326:071e761bcdcf

Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
author Michael Pavone <pavone@retrodev.com>
date Fri, 21 Apr 2017 23:35:32 -0700
parents 72ea3885e7b5
children e890971f3757
line wrap: on
line diff
--- a/tern.h	Fri Apr 21 01:22:52 2017 -0700
+++ b/tern.h	Fri Apr 21 23:35:32 2017 -0700
@@ -23,25 +23,33 @@
 	} straight;
 	struct tern_node *right;
 	char             el;
+	uint8_t          valtype;
 } tern_node;
 
-typedef void (*iter_fun)(char *key, tern_val val, void *data);
+enum {
+	TVAL_NONE=0,
+	TVAL_INT,
+	TVAL_PTR,
+	TVAL_NODE
+};
 
-tern_node * tern_insert(tern_node * head, char const * key, tern_val value);
-int tern_find(tern_node * head, char const * key, tern_val *ret);
+typedef void (*iter_fun)(char *key, tern_val val, uint8_t valtype, void *data);
+
+tern_node * tern_insert(tern_node * head, char const * key, tern_val value, uint8_t valtype);
+uint8_t tern_find(tern_node * head, char const * key, tern_val *ret);
 tern_node * tern_find_prefix(tern_node * head, char const * key);
 intptr_t tern_find_int(tern_node * head, char const * key, intptr_t def);
 tern_node * tern_insert_int(tern_node * head, char const * key, intptr_t value);
 void * tern_find_ptr_default(tern_node * head, char const * key, void * def);
 void * tern_find_ptr(tern_node * head, char const * key);
-tern_val tern_find_path_default(tern_node *head, char const *key, tern_val def);
-tern_val tern_find_path(tern_node *head, char const *key);
+tern_node *tern_find_node(tern_node *head, char const *key);
+tern_val tern_find_path_default(tern_node *head, char const *key, tern_val def, uint8_t req_valtype);
+tern_val tern_find_path(tern_node *head, char const *key, uint8_t valtype);
 tern_node * tern_insert_ptr(tern_node * head, char const * key, void * value);
 tern_node * tern_insert_node(tern_node *head, char const *key, tern_node *value);
 uint32_t tern_count(tern_node *head);
 void tern_foreach(tern_node *head, iter_fun fun, void *data);
 char * tern_int_key(uint32_t key, char * buf);
-tern_node * tern_get_node(tern_val value);
 void tern_free(tern_node *head);
 
 #endif //TERN_H_