diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-01-28 19:03:53 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-01-28 19:03:53 +0000 |
commit | 004dec2c2f44a0db510dfd65e5ffd8c9fc4ff83e (patch) | |
tree | a8b7de6debeb447af5479bf156706d09fe748ab4 /ext/http11/tst_search.c | |
parent | b6d34b2a4191a3118c7c70ea49349e89e581ed91 (diff) | |
download | unicorn-004dec2c2f44a0db510dfd65e5ffd8c9fc4ff83e.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@4 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'ext/http11/tst_search.c')
-rw-r--r-- | ext/http11/tst_search.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ext/http11/tst_search.c b/ext/http11/tst_search.c new file mode 100644 index 0000000..efa1cfa --- /dev/null +++ b/ext/http11/tst_search.c @@ -0,0 +1,54 @@ + +#include "tst.h" +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +void *tst_search(unsigned char *key, struct tst *tst, int *prefix_len) +{ + struct node *current_node; + 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; + + current_node = tst->head[(int)key[0]]; + key_index = 1; + + while (current_node != NULL) + { + if(key[key_index] == current_node->value) + { + if(current_node->value == 0) { + if(prefix_len) *prefix_len = key_index; + return current_node->middle; + } else { + current_node = current_node->middle; + key_index++; + continue; + } + } + else if( ((current_node->value == 0) && (key[key_index] < 64)) || + ((current_node->value != 0) && (key[key_index] < + current_node->value)) ) + { + current_node = current_node->left; + continue; + } + else + { + current_node = current_node->right; + continue; + } + } + + if(prefix_len) *prefix_len = key_index; + return NULL; +} |