diff options
author | David Robillard <d@drobilla.net> | 2011-09-19 06:14:03 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-09-19 06:14:03 +0000 |
commit | ed4eae3e4e8f90dc763106073e71d5fdd21eb898 (patch) | |
tree | 7fcff1f42335383147cd1f738c27d50061ad41c4 | |
parent | 37f37f06662d8098f82096ce46da3becab1992dc (diff) | |
download | zix-ed4eae3e4e8f90dc763106073e71d5fdd21eb898.tar.gz zix-ed4eae3e4e8f90dc763106073e71d5fdd21eb898.tar.bz2 zix-ed4eae3e4e8f90dc763106073e71d5fdd21eb898.zip |
Fix bugs
git-svn-id: http://svn.drobilla.net/zix/trunk@23 df6676b4-ccc9-40e5-b5d6-7c4628a128e3
-rw-r--r-- | src/patree.c | 20 | ||||
-rw-r--r-- | test/patree_test.c | 12 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/patree.c b/src/patree.c index 2ca0613..09a80f3 100644 --- a/src/patree.c +++ b/src/patree.c @@ -174,7 +174,6 @@ static ZixStatus patree_insert_internal(ZixPatreeNode* n, char* str, char* first, char* last) { n_edges_t child_i; - ZixPatreeNode* child; assert(first <= last); if (patree_find_edge(n, *first, &child_i)) { @@ -198,10 +197,17 @@ patree_insert_internal(ZixPatreeNode* n, char* str, char* first, char* last) patree_split_edge(child, split_i); return patree_insert_internal(child, str, first + split_i, last); } - } else if (label_len != split_i && split_i != s_len) { + } else if (label_len != split_i) { patree_split_edge(child, split_i); - patree_add_edge(child, str, first + split_i, last); + if (split_i != s_len) { + patree_add_edge(child, str, first + split_i, last); + } else { + assert(!child->str); + child->str = str; + } return ZIX_STATUS_SUCCESS; + } else if (label_len == s_len && !child->str) { + child->str = str; } else { return ZIX_STATUS_EXISTS; } @@ -223,11 +229,13 @@ zix_patree_insert(ZixPatree* t, const char* str) ZIX_API ZixStatus -zix_patree_find(ZixPatree* t, const char* p, char** match) +zix_patree_find(ZixPatree* t, const char* const str, char** match) { - ZixPatreeNode* n = t->root; + ZixPatreeNode* n = t->root; n_edges_t child_i; + const char* p = str; + *match = NULL; while (*p != '\0') { @@ -247,7 +255,7 @@ zix_patree_find(ZixPatree* t, const char* p, char** match) if (!*p) { /* Reached end of search string */ - if (!*l) { + if (l == label_last + 1) { /* Reached end of label string as well, match */ *match = child->str; return *match ? ZIX_STATUS_SUCCESS : ZIX_STATUS_NOT_FOUND; diff --git a/test/patree_test.c b/test/patree_test.c index 73a51ed..07d4a79 100644 --- a/test/patree_test.c +++ b/test/patree_test.c @@ -29,6 +29,18 @@ static const char* strings[] = { "http://example.net/baz", "http://drobilla.net/", "http://drobilla.net/software/zix", + "http://www.gbengasesan.com/blog", + "http://www.gbengasesan.com", + "http://echo.jpl.nasa.gov/~lance/delta_v/delta_v.rendezvous.html", + "http://echo.jpl.nasa.gov/asteroids/1986da/1986DA.html", + "http://echo.jpl.nasa.gov/", + "http://echo.jpl.nasa.gov/asteroids/1620_Geographos/geographos.html", + "http://echo.jpl.nasa.gov/~ostro/KY26/", + "http://echo.jpl.nasa.gov/~ostro/KY26/JPL_press_release.text", + "http://echo.jpl.nasa.gov", + "http://echo.jpl.nasa.gov/asteroids/4179_Toutatis/toutatis.html", + "http://echo.jpl.nasa.gov/asteroids/4769_Castalia/cast01.html", + "http://echo.jpl.nasa.gov/publications/review_abs.html", }; static int |