diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-02-02 06:53:32 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-02-02 06:53:32 +0000 |
commit | 1b9b3bcb734778037d7bc872e1c4d2290a7415e8 (patch) | |
tree | ba41c3c3c1dd9f94263c0ceff794fc7050503ed6 /ext/http11/tst_search.c | |
parent | 644d78fc0170c2ccf9551adba6def8815afbd4df (diff) | |
download | unicorn-1b9b3bcb734778037d7bc872e1c4d2290a7415e8.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@19 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'ext/http11/tst_search.c')
-rw-r--r-- | ext/http11/tst_search.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/ext/http11/tst_search.c b/ext/http11/tst_search.c index efa1cfa..4cfe6ff 100644 --- a/ext/http11/tst_search.c +++ b/ext/http11/tst_search.c @@ -7,18 +7,20 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len) { struct node *current_node; + void *longest_match = NULL; int key_index; assert(key != NULL && "key can't be NULL"); assert(tst != NULL && "tst can't be NULL"); - if(key[0] == 0) return NULL; if(tst->head[(int)key[0]] == NULL) return NULL; + + if(prefix_len) *prefix_len = 0; current_node = tst->head[(int)key[0]]; key_index = 1; @@ -30,7 +32,13 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len) if(prefix_len) *prefix_len = key_index; return current_node->middle; } else { + current_node = current_node->middle; + if(current_node && current_node->value == 0) { + if(prefix_len) *prefix_len = key_index+1; + longest_match = current_node->middle; + } + key_index++; continue; } @@ -39,16 +47,23 @@ void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len) ((current_node->value != 0) && (key[key_index] < current_node->value)) ) { + if(current_node->left && current_node->value == 0) { + if(prefix_len) *prefix_len = key_index; + longest_match = current_node->middle; + } current_node = current_node->left; continue; } else { + if(current_node->right && current_node->value == 0) { + if(prefix_len) *prefix_len = key_index; + longest_match = current_node->middle; + } current_node = current_node->right; continue; } } - if(prefix_len) *prefix_len = key_index; - return NULL; + return longest_match; } |