diff options
author | Michael Pavone <pavone@retrodev.com> | 2017-04-21 23:35:32 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2017-04-21 23:35:32 -0700 |
commit | 068d846fe4f627181a319418a17f6d54eb653999 (patch) | |
tree | 7be1693433822038fc5ea8950c274ac5a05f08a3 /tern.h | |
parent | e73ff9ec75a85c187c0a46bd4a79bf76282dd871 (diff) |
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
Diffstat (limited to 'tern.h')
-rw-r--r-- | tern.h | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -23,25 +23,33 @@ typedef struct tern_node { } 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_ |