nserver

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

commit ebe9b4e02b7d86e0a7b31dd9b129d20814072cca
parent 544398fdbe363ddff1980bbd9270554bdf050fa0
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri, 17 Apr 2020 20:33:24 -0400

nserver: Update TSTree_search_prefix.

* nserver/src/tstree.c (TSTree_search_prefix): Fix the largest prefix
matching key instead of the shortest.

Diffstat:
nserver/src/tstree.c | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/nserver/src/tstree.c b/nserver/src/tstree.c @@ -80,6 +80,7 @@ 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) { @@ -89,7 +90,7 @@ void *TSTree_search_prefix(TSTree *root, const char *key, size_t len) i++; if (i < len) { if (node->value) { - return node->value; + last = node->value; } node = node->equal; } @@ -98,7 +99,7 @@ void *TSTree_search_prefix(TSTree *root, const char *key, size_t len) } } - return NULL; + return last; } void TSTree_collect_keys(TSTree *node, char *key, size_t key_sz, DArray *array)