nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit e6f4ddb3eba6e475df7796b7a4e2fa2b07df755e
parent a70ebb56c004379d09c26dc22612498fde47836d
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon,  3 Feb 2020 23:22:38 -0500

nserver/src/tstree.c: Update TSTree_search_prefix.

Diffstat:
nserver/src/tstree.c | 16++++------------
1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/nserver/src/tstree.c b/nserver/src/tstree.c @@ -74,7 +74,6 @@ void *TSTree_search_prefix(TSTree *root, const char *key, size_t len) return NULL; TSTree *node = root; - TSTree *last = NULL; size_t i = 0; while (i < len && node) { @@ -83,8 +82,9 @@ void *TSTree_search_prefix(TSTree *root, const char *key, size_t len) } else if (key[i] == node->splitchar) { i++; if (i < len) { - if (node->value) - last = node; + if (node->value) { + return node->value; + } node = node->equal; } } else { @@ -92,15 +92,7 @@ void *TSTree_search_prefix(TSTree *root, const char *key, size_t len) } } - node = node ? node : last; - - // traverse until we find the first value in the equal chain - // this is then the first node with this prefix - while (node && !node->value) { - node = node->equal; - } - - return node ? node->value : NULL; + return NULL; } void TSTree_collect_keys(TSTree *node, char *key, size_t key_sz, DArray *array)