inline function optimization

This commit is contained in:
c9s 2014-05-16 18:57:36 +08:00
parent 134a849ecd
commit ebe4c008fb
5 changed files with 512 additions and 525 deletions

View file

@ -18,25 +18,25 @@ C API
```c
// create a router tree with 10 children capacity (this capacity can grow dynamically)
n = rtree_create(10);
n = r3_tree_create(10);
int route_data = 3;
// insert the route path into the router tree
rtree_insert_pathn(n , "/zoo" , strlen("/zoo") , &route_data );
rtree_insert_pathn(n , "/foo/bar" , strlen("/foo/bar") , &route_data );
rtree_insert_pathn(n , "/bar" , strlen("/bar") , &route_data );
rtree_insert_pathn(n , "/post/{id}" , strlen("/post/{id}") , &route_data );
r3_tree_insert_pathn(n , "/zoo" , strlen("/zoo") , &route_data );
r3_tree_insert_pathn(n , "/foo/bar" , strlen("/foo/bar") , &route_data );
r3_tree_insert_pathn(n , "/bar" , strlen("/bar") , &route_data );
r3_tree_insert_pathn(n , "/post/{id}" , strlen("/post/{id}") , &route_data );
// let's compile the tree!
rtree_compile(n);
r3_tree_compile(n);
// dump the compiled tree
rtree_dump(n, 0);
r3_tree_dump(n, 0);
// match a route
node *matched_node = rtree_match(n, "/foo/bar", strlen("/foo/bar") );
node *matched_node = r3_tree_match(n, "/foo/bar", strlen("/foo/bar") );
matched_node->endpoint; // make sure there is a route end at here.
int ret = *( (*int) matched_node->route_ptr );
```

View file

@ -2,5 +2,5 @@
arr = ["foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply"]
paths = arr.permutation(3).map { |a| "/#{a.join '/'}" }
paths.each do |path|
puts "rtree_insert_path(n, \"#{path}\", NULL);"
puts "r3_tree_insert_path(n, \"#{path}\", NULL);"
end

View file

@ -23,8 +23,8 @@ typedef struct _node node;
struct _node {
edge ** edges;
int edge_len;
int edge_cap;
int r3_edge_len;
int r3_edge_cap;
/* the combined regexp pattern string from pattern_tokens */
char * combined_pattern;
@ -55,44 +55,44 @@ typedef struct {
} match_entry;
node * rtree_create(int cap);
node * r3_tree_create(int cap);
node * node_create();
node * r3_node_create();
void rtree_free(node * tree);
void r3_tree_free(node * tree);
void edge_free(edge * edge);
void r3_edge_free(edge * edge);
edge * rtree_add_child(node * n, char * pat , node *child);
edge * r3_tree_add_child(node * n, char * pat , node *child);
edge * node_find_edge(node * n, char * pat);
edge * r3_node_find_edge(node * n, char * pat);
void rtree_append_edge(node *n, edge *child);
void r3_tree_append_edge(node *n, edge *child);
node * rtree_insert_path(node *tree, char *route, void * route_ptr);
node * r3_tree_insert_path(node *tree, char *route, void * route_ptr);
node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr);
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr);
void rtree_dump(node * n, int level);
void r3_tree_dump(node * n, int level);
edge * node_find_edge_str(node * n, char * str, int str_len);
edge * r3_node_find_edge_str(node * n, char * str, int str_len);
void rtree_compile(node *n);
void r3_tree_compile(node *n);
void rtree_compile_patterns(node * n);
void r3_tree_compile_patterns(node * n);
node * rtree_match(node * n, char * path, int path_len, match_entry * entry);
node * r3_tree_match(node * n, char * path, int path_len, match_entry * entry);
bool node_has_slug_edges(node *n);
bool r3_node_has_slug_edges(node *n);
node * rtree_lookup(node * tree, char * path, int path_len);
node * r3_tree_lookup(node * tree, char * path, int path_len);
edge * edge_create(char * pattern, int pattern_len, node * child);
edge * r3_edge_create(char * pattern, int pattern_len, node * child);
void edge_branch(edge *e, int dl);
void r3_edge_branch(edge *e, int dl);
void edge_free(edge * edge);
void r3_edge_free(edge * edge);

View file

@ -23,21 +23,21 @@
/**
* Create a node object
*/
node * rtree_create(int cap) {
node * r3_tree_create(int cap) {
node * n = (node*) malloc( sizeof(node) );
n->edges = (edge**) malloc( sizeof(edge*) * 10 );
n->edge_len = 0;
n->edge_cap = 10;
n->r3_edge_len = 0;
n->r3_edge_cap = 10;
n->endpoint = 0;
n->combined_pattern = NULL;
return n;
}
void rtree_free(node * tree) {
for (int i = 0 ; i < tree->edge_len ; i++ ) {
void r3_tree_free(node * tree) {
for (int i = 0 ; i < tree->r3_edge_len ; i++ ) {
if (tree->edges[i]) {
edge_free(tree->edges[ i ]);
r3_edge_free(tree->edges[ i ]);
}
}
@ -45,7 +45,7 @@ void rtree_free(node * tree) {
free(tree->combined_pattern);
free(tree->edges);
// str_array_free(tree->edge_patterns);
// str_array_free(tree->r3_edge_patterns);
free(tree);
tree = NULL;
}
@ -53,42 +53,42 @@ void rtree_free(node * tree) {
/* parent node, edge pattern, child */
edge * rtree_add_child(node * n, char * pat , node *child) {
edge * r3_tree_add_child(node * n, char * pat , node *child) {
// find the same sub-pattern, if it does not exist, create one
edge * e;
e = node_find_edge(n, pat);
e = r3_node_find_edge(n, pat);
if (e) {
return e;
}
e = edge_create( pat, strlen(pat), child);
rtree_append_edge(n, e);
// str_array_append(n->edge_patterns, pat);
// assert( str_array_len(n->edge_patterns) == n->edge_len );
e = r3_edge_create( pat, strlen(pat), child);
r3_tree_append_edge(n, e);
// str_array_append(n->r3_edge_patterns, pat);
// assert( str_array_len(n->r3_edge_patterns) == n->r3_edge_len );
return e;
}
void rtree_append_edge(node *n, edge *e) {
void r3_tree_append_edge(node *n, edge *e) {
if (!n->edges) {
n->edge_cap = 3;
n->edges = malloc(sizeof(edge) * n->edge_cap);
n->r3_edge_cap = 3;
n->edges = malloc(sizeof(edge) * n->r3_edge_cap);
}
if (n->edge_len >= n->edge_cap) {
n->edge_cap *= 2;
n->edges = realloc(n->edges, sizeof(edge) * n->edge_cap);
if (n->r3_edge_len >= n->r3_edge_cap) {
n->r3_edge_cap *= 2;
n->edges = realloc(n->edges, sizeof(edge) * n->r3_edge_cap);
}
n->edges[ n->edge_len++ ] = e;
n->edges[ n->r3_edge_len++ ] = e;
}
edge * node_find_edge(node * n, char * pat) {
edge * r3_node_find_edge(node * n, char * pat) {
edge * e;
for (int i = 0 ; i < n->edge_len ; i++ ) {
for (int i = 0 ; i < n->r3_edge_len ; i++ ) {
e = n->edges[i];
if ( strcmp(e->pattern, pat) == 0 ) {
return e;
@ -97,18 +97,18 @@ edge * node_find_edge(node * n, char * pat) {
return NULL;
}
void rtree_compile(node *n)
void r3_tree_compile(node *n)
{
bool use_slug = node_has_slug_edges(n);
bool use_slug = r3_node_has_slug_edges(n);
if ( use_slug ) {
rtree_compile_patterns(n);
r3_tree_compile_patterns(n);
} else {
// use normal text matching...
n->combined_pattern = NULL;
}
for (int i = 0 ; i < n->edge_len ; i++ ) {
rtree_compile(n->edges[i]->child);
for (int i = 0 ; i < n->r3_edge_len ; i++ ) {
r3_tree_compile(n->edges[i]->child);
}
}
@ -117,7 +117,7 @@ void rtree_compile(node *n)
* This function combines ['/foo', '/bar', '/{slug}'] into (/foo)|(/bar)|/([^/]+)}
*
*/
void rtree_compile_patterns(node * n) {
void r3_tree_compile_patterns(node * n) {
char * cpat;
char * p;
@ -127,9 +127,11 @@ void rtree_compile_patterns(node * n) {
p = cpat;
strncat(p, "^", 1);
p++;
edge *e = NULL;
for ( int i = 0 ; i < n->edge_len ; i++ ) {
for ( int i = 0 ; i < n->r3_edge_len ; i++ ) {
e = n->edges[i];
if ( e->has_slug ) {
char * slug_pat = compile_slug(e->pattern, e->pattern_len);
@ -143,7 +145,7 @@ void rtree_compile_patterns(node * n) {
strncat(p++,")", 1);
}
if ( i + 1 < n->edge_len ) {
if ( i + 1 < n->r3_edge_len ) {
strncat(p++,"|",1);
}
}
@ -181,18 +183,23 @@ void rtree_compile_patterns(node * n) {
node * rtree_match(node * n, char * path, int path_len, match_entry * entry) {
node * r3_tree_match(node * n, char * path, int path_len, match_entry * entry) {
// info("try matching: %s\n", path);
edge *e;
if (n->combined_pattern && n->pcre_pattern) {
info("pcre matching %s on %s\n", n->combined_pattern, path);
// int ovector_count = (n->edge_len + 1) * 2;
// int ovector_count = (n->r3_edge_len + 1) * 2;
int ovector_count = 30;
int ovector[ovector_count];
int rc;
int i;
rc = pcre_exec(
n->pcre_pattern, /* the compiled pattern */
NULL, /* no extra data - we didn't study the pattern */
// PCRE Study makes this slow
NULL, // n->pcre_extra, /* no extra data - we didn't study the pattern */
path, /* the subject string */
path_len, /* the length of the subject */
0, /* start at offset 0 in the subject */
@ -214,8 +221,6 @@ node * rtree_match(node * n, char * path, int path_len, match_entry * entry) {
return NULL;
}
int i;
edge *e;
for (i = 1; i < rc; i++)
{
char *substring_start = path + ovector[2*i];
@ -224,75 +229,57 @@ node * rtree_match(node * n, char * path, int path_len, match_entry * entry) {
if ( substring_length > 0) {
int restlen = path_len - ovector[2*i+1]; // fully match to the end
info("matched item => restlen:%d edges:%d i:%d\n", restlen, n->edge_len, i);
info("matched item => restlen:%d edges:%d i:%d\n", restlen, n->r3_edge_len, i);
e = n->edges[i - 1];
if (entry && e->has_slug) {
// entry->
}
if (restlen == 0) {
return e->child;
}
return rtree_match( e->child, substring_start + substring_length, restlen, entry);
return r3_tree_match( e->child, substring_start + substring_length, restlen, entry);
}
}
// does not match
return NULL;
}
edge *e = node_find_edge_str(n, path, path_len);
e = r3_node_find_edge_str(n, path, path_len);
if (e) {
int len = path_len - e->pattern_len;
if(len == 0) {
return e->child;
int restlen = path_len - e->pattern_len;
if(restlen) {
return r3_tree_match(e->child, path + e->pattern_len, restlen, entry);
} else {
return rtree_match(e->child, path + e->pattern_len, len, entry);
return e->child;
}
}
return NULL;
}
edge * node_find_edge_str(node * n, char * str, int str_len) {
edge *e;
char *p;
char *s;
for ( int i = 0 ; i < n->edge_len ; i++ ) {
e = n->edges[i];
p = e->pattern;
s = str;
#define node_edge_pattern(node,i) node->edges[i]->pattern
#define node_edge_pattern_len(node,i) node->edges[i]->pattern_len
info("matching '%s' with '%s'\n", str, e->pattern);
if ( str_len < e->pattern_len ) {
continue;
inline edge * r3_node_find_edge_str(node * n, char * str, int str_len) {
int i = 0;
for (; i < n->r3_edge_len ; i++ ) {
info("matching '%s' with '%s'\n", str, node_edge_pattern(n,i) );
if ( strncmp( node_edge_pattern(n,i), str, node_edge_pattern_len(n,i) ) == 0 ) {
return n->edges[i];
}
if ( strncmp(e->pattern, str, e->pattern_len) == 0 ) {
return e;
}
/*
while ( *p == *s ) {
p++;
s++;
}
info("matched len: %d == pattern len %d\n", (int)(p - e->pattern) , e->pattern_len);
if ( p - e->pattern == e->pattern_len ) {
return e;
}
*/
}
return NULL;
}
node * rtree_lookup(node * tree, char * path, int path_len) {
node * r3_tree_lookup(node * tree, char * path, int path_len) {
str_array * tokens = split_route_pattern(path, path_len);
node * n = tree;
edge * e = NULL;
for ( int i = 0 ; i < tokens->len ; i++ ) {
e = node_find_edge(n, str_array_fetch(tokens, i) );
e = r3_node_find_edge(n, str_array_fetch(tokens, i) );
if (!e) {
return NULL;
}
@ -304,11 +291,11 @@ node * rtree_lookup(node * tree, char * path, int path_len) {
return NULL;
}
node * node_create() {
node * r3_node_create() {
node * n = (node*) malloc( sizeof(node) );
n->edges = NULL;
n->edge_len = 0;
n->edge_cap = 0;
n->r3_edge_len = 0;
n->r3_edge_cap = 0;
n->endpoint = 0;
n->combined_pattern = NULL;
n->pcre_pattern = NULL;
@ -316,12 +303,12 @@ node * node_create() {
}
node * rtree_insert_path(node *tree, char *route, void * route_ptr)
node * r3_tree_insert_path(node *tree, char *route, void * route_ptr)
{
return rtree_insert_pathn(tree, route, strlen(route) , route_ptr);
return r3_tree_insert_pathn(tree, route, strlen(route) , route_ptr);
}
node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr)
node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route_ptr)
{
node * n = tree;
edge * e = NULL;
@ -330,7 +317,7 @@ node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_p
/* length of common prefix */
int dl = 0;
for( int i = 0 ; i < n->edge_len ; i++ ) {
for( int i = 0 ; i < n->r3_edge_len ; i++ ) {
dl = strndiff(route, n->edges[i]->pattern, n->edges[i]->pattern_len);
// printf("dl: %d %s vs %s\n", dl, route, n->edges[i]->pattern );
@ -354,8 +341,8 @@ node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_p
if ( dl == 0 ) {
// not found, we should just insert a whole new edge
node * child = rtree_create(3);
rtree_add_child(n, strndup(route, route_len) , child);
node * child = r3_tree_create(3);
r3_tree_add_child(n, strndup(route, route_len) , child);
info("edge not found, insert one: %s\n", route);
child->route_ptr = route_ptr;
child->endpoint++;
@ -367,7 +354,7 @@ node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_p
// there are something more we can insert
if ( subroute_len > 0 ) {
return rtree_insert_pathn(e->child, subroute, subroute_len, route_ptr);
return r3_tree_insert_pathn(e->child, subroute, subroute_len, route_ptr);
} else {
// no more,
e->child->endpoint++; // make it as an endpoint, TODO: put the route value
@ -387,14 +374,14 @@ node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_p
char * s2 = route + dl;
int s2_len = 0;
edge_branch(e, dl);
r3_edge_branch(e, dl);
// here is the new edge from.
c2 = rtree_create(3);
c2 = r3_tree_create(3);
s2_len = route_len - dl;
e2 = edge_create(strndup(s2, s2_len), s2_len, c2);
e2 = r3_edge_create(strndup(s2, s2_len), s2_len, c2);
// printf("edge right: %s\n", e2->pattern);
rtree_append_edge(e->child, e2);
r3_tree_append_edge(e->child, e2);
// truncate the original edge pattern
free(e->pattern);
@ -412,10 +399,10 @@ node * rtree_insert_pathn(node *tree, char *route, int route_len, void * route_p
return n;
}
bool node_has_slug_edges(node *n) {
bool r3_node_has_slug_edges(node *n) {
bool found = FALSE;
edge *e;
for ( int i = 0 ; i < n->edge_len ; i++ ) {
for ( int i = 0 ; i < n->r3_edge_len ; i++ ) {
e = n->edges[i];
e->has_slug = contains_slug(e->pattern);
if (e->has_slug)
@ -429,37 +416,37 @@ bool node_has_slug_edges(node *n) {
* branch the edge pattern at "dl" offset
*
*/
void edge_branch(edge *e, int dl) {
void r3_edge_branch(edge *e, int dl) {
node *c1; // child 1, child 2
edge *e1; // edge 1, edge 2
char * s1 = e->pattern + dl;
int s1_len = 0;
edge **tmp_edges = e->child->edges;
int tmp_edge_len = e->child->edge_len;
int tmp_r3_edge_len = e->child->r3_edge_len;
// the suffix edge of the leaf
c1 = rtree_create(3);
c1 = r3_tree_create(3);
s1_len = e->pattern_len - dl;
e1 = edge_create(strndup(s1, s1_len), s1_len, c1);
e1 = r3_edge_create(strndup(s1, s1_len), s1_len, c1);
// printf("edge left: %s\n", e1->pattern);
// Migrate the child edges to the new edge we just created.
for ( int i = 0 ; i < tmp_edge_len ; i++ ) {
rtree_append_edge(c1, tmp_edges[i]);
for ( int i = 0 ; i < tmp_r3_edge_len ; i++ ) {
r3_tree_append_edge(c1, tmp_edges[i]);
e->child->edges[i] = NULL;
}
e->child->edge_len = 0;
e->child->r3_edge_len = 0;
e->child->endpoint--;
info("branched pattern: %s\n", e1->pattern);
rtree_append_edge(e->child, e1);
r3_tree_append_edge(e->child, e1);
c1->endpoint++;
}
edge * edge_create(char * pattern, int pattern_len, node * child) {
edge * r3_edge_create(char * pattern, int pattern_len, node * child) {
edge * e = (edge*) malloc( sizeof(edge) );
e->pattern = pattern;
e->pattern_len = pattern_len;
@ -467,27 +454,27 @@ edge * edge_create(char * pattern, int pattern_len, node * child) {
return e;
}
void edge_free(edge * e) {
void r3_edge_free(edge * e) {
if (e->pattern) {
free(e->pattern);
}
if ( e->child ) {
rtree_free(e->child);
r3_tree_free(e->child);
}
}
void rtree_dump(node * n, int level) {
if ( n->edge_len ) {
void r3_tree_dump(node * n, int level) {
if ( n->r3_edge_len ) {
if ( n->combined_pattern ) {
printf(" regexp:%s", n->combined_pattern);
}
printf(" endpoint:%d\n", n->endpoint);
for ( int i = 0 ; i < n->edge_len ; i++ ) {
for ( int i = 0 ; i < n->r3_edge_len ; i++ ) {
edge * e = n->edges[i];
print_indent(level);
printf(" |-\"%s\"", e->pattern);
@ -498,7 +485,7 @@ void rtree_dump(node * n, int level) {
}
if ( e->child && e->child->edges ) {
rtree_dump( e->child, level + 1);
r3_tree_dump( e->child, level + 1);
}
printf("\n");
}
@ -506,7 +493,7 @@ void rtree_dump(node * n, int level) {
}
/*
char * node_trace(node * n) {
char * r3_node_trace(node * n) {
}
*/

View file

@ -44,31 +44,31 @@ START_TEST (test_ltrim_slash)
}
END_TEST
START_TEST (test_node_construct_uniq)
START_TEST (test_r3_node_construct_uniq)
{
node * n = rtree_create(10);
node * n = r3_tree_create(10);
node * child = rtree_create(3);
node * child = r3_tree_create(3);
// fail_if( rtree_add_child(n, strdup("/add") , child) != NULL );
// fail_if( rtree_add_child(n, strdup("/add") , child) != NULL );
// fail_if( r3_tree_add_child(n, strdup("/add") , child) != NULL );
// fail_if( r3_tree_add_child(n, strdup("/add") , child) != NULL );
rtree_free(n);
r3_tree_free(n);
}
END_TEST
START_TEST (test_node_find_edge)
START_TEST (test_r3_node_find_edge)
{
node * n = rtree_create(10);
node * n = r3_tree_create(10);
node * child = rtree_create(3);
node * child = r3_tree_create(3);
fail_if( rtree_add_child(n, strdup("/add") , child) == FALSE );
fail_if( r3_tree_add_child(n, strdup("/add") , child) == FALSE );
fail_if( node_find_edge(n, "/add") == NULL );
fail_if( node_find_edge(n, "/bar") != NULL );
fail_if( r3_node_find_edge(n, "/add") == NULL );
fail_if( r3_node_find_edge(n, "/bar") != NULL );
rtree_free(n);
r3_tree_free(n);
}
END_TEST
@ -77,35 +77,35 @@ START_TEST (test_compile)
{
str_array *t;
node * n;
n = rtree_create(10);
n = r3_tree_create(10);
match_entry * entry;
node *m;
edge *e ;
rtree_insert_pathn(n, "/zoo", strlen("/zoo"), NULL);
rtree_insert_pathn(n, "/foo", strlen("/foo"), NULL);
rtree_insert_pathn(n, "/bar", strlen("/bar"), NULL);
rtree_compile(n);
r3_tree_insert_pathn(n, "/zoo", strlen("/zoo"), NULL);
r3_tree_insert_pathn(n, "/foo", strlen("/foo"), NULL);
r3_tree_insert_pathn(n, "/bar", strlen("/bar"), NULL);
r3_tree_compile(n);
fail_if( n->combined_pattern );
fail_if( NULL == node_find_edge_str(n, "/", strlen("/") ) );
fail_if( NULL == r3_node_find_edge_str(n, "/", strlen("/") ) );
#ifdef DEBUG
rtree_dump(n, 0);
r3_tree_dump(n, 0);
#endif
rtree_insert_pathn(n, "/foo/{id}", strlen("/foo/{id}"), NULL);
rtree_insert_pathn(n, "/{id}", strlen("/{id}"), NULL);
rtree_compile(n);
rtree_compile(n); // test double compile
r3_tree_insert_pathn(n, "/foo/{id}", strlen("/foo/{id}"), NULL);
r3_tree_insert_pathn(n, "/{id}", strlen("/{id}"), NULL);
r3_tree_compile(n);
r3_tree_compile(n); // test double compile
#ifdef DEBUG
rtree_dump(n, 0);
r3_tree_dump(n, 0);
#endif
/*
fail_if(n->edges[0]->child->combined_pattern == NULL);
e = node_find_edge_str(n, "/", strlen("/") );
e = r3_node_find_edge_str(n, "/", strlen("/") );
fail_if( NULL == e );
*/
/*
@ -118,22 +118,22 @@ START_TEST (test_compile)
entry = calloc( sizeof(entry) , 1 );
m = rtree_match( n , "/foo", strlen("/foo"), entry);
m = r3_tree_match( n , "/foo", strlen("/foo"), entry);
fail_if( NULL == m );
m = rtree_match( n , "/zoo", strlen("/zoo"), entry);
m = r3_tree_match( n , "/zoo", strlen("/zoo"), entry);
fail_if( NULL == m );
m = rtree_match( n , "/bar", strlen("/bar"), entry);
m = r3_tree_match( n , "/bar", strlen("/bar"), entry);
fail_if( NULL == m );
m = rtree_match( n , "/xxx", strlen("/xxx"), entry);
m = r3_tree_match( n , "/xxx", strlen("/xxx"), entry);
fail_if( NULL == m );
m = rtree_match( n , "/foo/xxx", strlen("/foo/xxx"), entry);
m = r3_tree_match( n , "/foo/xxx", strlen("/foo/xxx"), entry);
fail_if( NULL == m );
m = rtree_match( n , "/some_id", strlen("/some_id"), entry);
m = r3_tree_match( n , "/some_id", strlen("/some_id"), entry);
fail_if( NULL == m );
ck_assert_int_gt( m->endpoint , 0 ); // should not be an endpoint
}
@ -184,38 +184,38 @@ START_TEST (test_compile_slug)
END_TEST
START_TEST (test_rtree_insert_pathn)
START_TEST (test_r3_tree_insert_pathn)
{
node * n = rtree_create(10);
node * n = r3_tree_create(10);
info("Inserting /foo/bar\n");
rtree_insert_path(n, "/foo/bar", NULL);
// rtree_dump(n, 0);
r3_tree_insert_path(n, "/foo/bar", NULL);
// r3_tree_dump(n, 0);
info("Inserting /foo/zoo\n");
rtree_insert_path(n, "/foo/zoo", NULL);
// rtree_dump(n, 0);
r3_tree_insert_path(n, "/foo/zoo", NULL);
// r3_tree_dump(n, 0);
info("Inserting /f/id\n");
rtree_insert_path(n, "/f/id" , NULL);
// rtree_dump(n, 0);
r3_tree_insert_path(n, "/f/id" , NULL);
// r3_tree_dump(n, 0);
info("Inserting /post/{id}\n");
rtree_insert_pathn(n, "/post/{id}", strlen("/post/{id}"), NULL);
// rtree_dump(n, 0);
r3_tree_insert_pathn(n, "/post/{id}", strlen("/post/{id}"), NULL);
// r3_tree_dump(n, 0);
info("Inserting /post/{handle}\n");
rtree_insert_pathn(n, "/post/{handle}", strlen("/post/{handle}"), NULL);
// rtree_dump(n, 0);
r3_tree_insert_pathn(n, "/post/{handle}", strlen("/post/{handle}"), NULL);
// r3_tree_dump(n, 0);
info("Inserting /post/{handle}-{id}\n");
rtree_insert_pathn(n, "/post/{handle}-{id}", strlen("/post/{handle}-{id}"), NULL);
rtree_compile(n);
r3_tree_insert_pathn(n, "/post/{handle}-{id}", strlen("/post/{handle}-{id}"), NULL);
r3_tree_compile(n);
#ifdef DEBUG
rtree_dump(n, 0);
r3_tree_dump(n, 0);
#endif
rtree_free(n);
r3_tree_free(n);
}
END_TEST
@ -284,353 +284,353 @@ END_TEST
START_TEST(benchmark_str)
{
match_entry * entry = calloc( sizeof(entry) , 1 );
node * n = rtree_create(1);
node * n = r3_tree_create(1);
rtree_insert_path(n, "/foo/bar/baz", NULL);
rtree_insert_path(n, "/foo/bar/qux", NULL);
rtree_insert_path(n, "/foo/bar/quux", NULL);
rtree_insert_path(n, "/foo/bar/corge", NULL);
rtree_insert_path(n, "/foo/bar/grault", NULL);
rtree_insert_path(n, "/foo/bar/garply", NULL);
rtree_insert_path(n, "/foo/baz/bar", NULL);
rtree_insert_path(n, "/foo/baz/qux", NULL);
rtree_insert_path(n, "/foo/baz/quux", NULL);
rtree_insert_path(n, "/foo/baz/corge", NULL);
rtree_insert_path(n, "/foo/baz/grault", NULL);
rtree_insert_path(n, "/foo/baz/garply", NULL);
rtree_insert_path(n, "/foo/qux/bar", NULL);
rtree_insert_path(n, "/foo/qux/baz", NULL);
rtree_insert_path(n, "/foo/qux/quux", NULL);
rtree_insert_path(n, "/foo/qux/corge", NULL);
rtree_insert_path(n, "/foo/qux/grault", NULL);
rtree_insert_path(n, "/foo/qux/garply", NULL);
rtree_insert_path(n, "/foo/quux/bar", NULL);
rtree_insert_path(n, "/foo/quux/baz", NULL);
rtree_insert_path(n, "/foo/quux/qux", NULL);
rtree_insert_path(n, "/foo/quux/corge", NULL);
rtree_insert_path(n, "/foo/quux/grault", NULL);
rtree_insert_path(n, "/foo/quux/garply", NULL);
rtree_insert_path(n, "/foo/corge/bar", NULL);
rtree_insert_path(n, "/foo/corge/baz", NULL);
rtree_insert_path(n, "/foo/corge/qux", NULL);
rtree_insert_path(n, "/foo/corge/quux", NULL);
rtree_insert_path(n, "/foo/corge/grault", NULL);
rtree_insert_path(n, "/foo/corge/garply", NULL);
rtree_insert_path(n, "/foo/grault/bar", NULL);
rtree_insert_path(n, "/foo/grault/baz", NULL);
rtree_insert_path(n, "/foo/grault/qux", NULL);
rtree_insert_path(n, "/foo/grault/quux", NULL);
rtree_insert_path(n, "/foo/grault/corge", NULL);
rtree_insert_path(n, "/foo/grault/garply", NULL);
rtree_insert_path(n, "/foo/garply/bar", NULL);
rtree_insert_path(n, "/foo/garply/baz", NULL);
rtree_insert_path(n, "/foo/garply/qux", NULL);
rtree_insert_path(n, "/foo/garply/quux", NULL);
rtree_insert_path(n, "/foo/garply/corge", NULL);
rtree_insert_path(n, "/foo/garply/grault", NULL);
rtree_insert_path(n, "/bar/foo/baz", NULL);
rtree_insert_path(n, "/bar/foo/qux", NULL);
rtree_insert_path(n, "/bar/foo/quux", NULL);
rtree_insert_path(n, "/bar/foo/corge", NULL);
rtree_insert_path(n, "/bar/foo/grault", NULL);
rtree_insert_path(n, "/bar/foo/garply", NULL);
rtree_insert_path(n, "/bar/baz/foo", NULL);
rtree_insert_path(n, "/bar/baz/qux", NULL);
rtree_insert_path(n, "/bar/baz/quux", NULL);
rtree_insert_path(n, "/bar/baz/corge", NULL);
rtree_insert_path(n, "/bar/baz/grault", NULL);
rtree_insert_path(n, "/bar/baz/garply", NULL);
rtree_insert_path(n, "/bar/qux/foo", NULL);
rtree_insert_path(n, "/bar/qux/baz", NULL);
rtree_insert_path(n, "/bar/qux/quux", NULL);
rtree_insert_path(n, "/bar/qux/corge", NULL);
rtree_insert_path(n, "/bar/qux/grault", NULL);
rtree_insert_path(n, "/bar/qux/garply", NULL);
rtree_insert_path(n, "/bar/quux/foo", NULL);
rtree_insert_path(n, "/bar/quux/baz", NULL);
rtree_insert_path(n, "/bar/quux/qux", NULL);
rtree_insert_path(n, "/bar/quux/corge", NULL);
rtree_insert_path(n, "/bar/quux/grault", NULL);
rtree_insert_path(n, "/bar/quux/garply", NULL);
rtree_insert_path(n, "/bar/corge/foo", NULL);
rtree_insert_path(n, "/bar/corge/baz", NULL);
rtree_insert_path(n, "/bar/corge/qux", NULL);
rtree_insert_path(n, "/bar/corge/quux", NULL);
rtree_insert_path(n, "/bar/corge/grault", NULL);
rtree_insert_path(n, "/bar/corge/garply", NULL);
rtree_insert_path(n, "/bar/grault/foo", NULL);
rtree_insert_path(n, "/bar/grault/baz", NULL);
rtree_insert_path(n, "/bar/grault/qux", NULL);
rtree_insert_path(n, "/bar/grault/quux", NULL);
rtree_insert_path(n, "/bar/grault/corge", NULL);
rtree_insert_path(n, "/bar/grault/garply", NULL);
rtree_insert_path(n, "/bar/garply/foo", NULL);
rtree_insert_path(n, "/bar/garply/baz", NULL);
rtree_insert_path(n, "/bar/garply/qux", NULL);
rtree_insert_path(n, "/bar/garply/quux", NULL);
rtree_insert_path(n, "/bar/garply/corge", NULL);
rtree_insert_path(n, "/bar/garply/grault", NULL);
rtree_insert_path(n, "/baz/foo/bar", NULL);
rtree_insert_path(n, "/baz/foo/qux", NULL);
rtree_insert_path(n, "/baz/foo/quux", NULL);
rtree_insert_path(n, "/baz/foo/corge", NULL);
rtree_insert_path(n, "/baz/foo/grault", NULL);
rtree_insert_path(n, "/baz/foo/garply", NULL);
rtree_insert_path(n, "/baz/bar/foo", NULL);
rtree_insert_path(n, "/baz/bar/qux", NULL);
rtree_insert_path(n, "/baz/bar/quux", NULL);
rtree_insert_path(n, "/baz/bar/corge", NULL);
rtree_insert_path(n, "/baz/bar/grault", NULL);
rtree_insert_path(n, "/baz/bar/garply", NULL);
rtree_insert_path(n, "/baz/qux/foo", NULL);
rtree_insert_path(n, "/baz/qux/bar", NULL);
rtree_insert_path(n, "/baz/qux/quux", NULL);
rtree_insert_path(n, "/baz/qux/corge", NULL);
rtree_insert_path(n, "/baz/qux/grault", NULL);
rtree_insert_path(n, "/baz/qux/garply", NULL);
rtree_insert_path(n, "/baz/quux/foo", NULL);
rtree_insert_path(n, "/baz/quux/bar", NULL);
rtree_insert_path(n, "/baz/quux/qux", NULL);
rtree_insert_path(n, "/baz/quux/corge", NULL);
rtree_insert_path(n, "/baz/quux/grault", NULL);
rtree_insert_path(n, "/baz/quux/garply", NULL);
rtree_insert_path(n, "/baz/corge/foo", NULL);
rtree_insert_path(n, "/baz/corge/bar", NULL);
rtree_insert_path(n, "/baz/corge/qux", NULL);
rtree_insert_path(n, "/baz/corge/quux", NULL);
rtree_insert_path(n, "/baz/corge/grault", NULL);
rtree_insert_path(n, "/baz/corge/garply", NULL);
rtree_insert_path(n, "/baz/grault/foo", NULL);
rtree_insert_path(n, "/baz/grault/bar", NULL);
rtree_insert_path(n, "/baz/grault/qux", NULL);
rtree_insert_path(n, "/baz/grault/quux", NULL);
rtree_insert_path(n, "/baz/grault/corge", NULL);
rtree_insert_path(n, "/baz/grault/garply", NULL);
rtree_insert_path(n, "/baz/garply/foo", NULL);
rtree_insert_path(n, "/baz/garply/bar", NULL);
rtree_insert_path(n, "/baz/garply/qux", NULL);
rtree_insert_path(n, "/baz/garply/quux", NULL);
rtree_insert_path(n, "/baz/garply/corge", NULL);
rtree_insert_path(n, "/baz/garply/grault", NULL);
rtree_insert_path(n, "/qux/foo/bar", NULL);
rtree_insert_path(n, "/qux/foo/baz", NULL);
rtree_insert_path(n, "/qux/foo/quux", NULL);
rtree_insert_path(n, "/qux/foo/corge", NULL);
rtree_insert_path(n, "/qux/foo/grault", NULL);
rtree_insert_path(n, "/qux/foo/garply", NULL);
rtree_insert_path(n, "/qux/bar/foo", NULL);
rtree_insert_path(n, "/qux/bar/baz", NULL);
rtree_insert_path(n, "/qux/bar/quux", NULL);
rtree_insert_path(n, "/qux/bar/corge", (void*) 999);
rtree_insert_path(n, "/qux/bar/grault", NULL);
rtree_insert_path(n, "/qux/bar/garply", NULL);
rtree_insert_path(n, "/qux/baz/foo", NULL);
rtree_insert_path(n, "/qux/baz/bar", NULL);
rtree_insert_path(n, "/qux/baz/quux", NULL);
rtree_insert_path(n, "/qux/baz/corge", NULL);
rtree_insert_path(n, "/qux/baz/grault", NULL);
rtree_insert_path(n, "/qux/baz/garply", NULL);
rtree_insert_path(n, "/qux/quux/foo", NULL);
rtree_insert_path(n, "/qux/quux/bar", NULL);
rtree_insert_path(n, "/qux/quux/baz", NULL);
rtree_insert_path(n, "/qux/quux/corge", NULL);
rtree_insert_path(n, "/qux/quux/grault", NULL);
rtree_insert_path(n, "/qux/quux/garply", NULL);
rtree_insert_path(n, "/qux/corge/foo", NULL);
rtree_insert_path(n, "/qux/corge/bar", NULL);
rtree_insert_path(n, "/qux/corge/baz", NULL);
rtree_insert_path(n, "/qux/corge/quux", NULL);
rtree_insert_path(n, "/qux/corge/grault", NULL);
rtree_insert_path(n, "/qux/corge/garply", NULL);
rtree_insert_path(n, "/qux/grault/foo", NULL);
rtree_insert_path(n, "/qux/grault/bar", NULL);
rtree_insert_path(n, "/qux/grault/baz", NULL);
rtree_insert_path(n, "/qux/grault/quux", NULL);
rtree_insert_path(n, "/qux/grault/corge", NULL);
rtree_insert_path(n, "/qux/grault/garply", NULL);
rtree_insert_path(n, "/qux/garply/foo", NULL);
rtree_insert_path(n, "/qux/garply/bar", NULL);
rtree_insert_path(n, "/qux/garply/baz", NULL);
rtree_insert_path(n, "/qux/garply/quux", NULL);
rtree_insert_path(n, "/qux/garply/corge", NULL);
rtree_insert_path(n, "/qux/garply/grault", NULL);
rtree_insert_path(n, "/quux/foo/bar", NULL);
rtree_insert_path(n, "/quux/foo/baz", NULL);
rtree_insert_path(n, "/quux/foo/qux", NULL);
rtree_insert_path(n, "/quux/foo/corge", NULL);
rtree_insert_path(n, "/quux/foo/grault", NULL);
rtree_insert_path(n, "/quux/foo/garply", NULL);
rtree_insert_path(n, "/quux/bar/foo", NULL);
rtree_insert_path(n, "/quux/bar/baz", NULL);
rtree_insert_path(n, "/quux/bar/qux", NULL);
rtree_insert_path(n, "/quux/bar/corge", NULL);
rtree_insert_path(n, "/quux/bar/grault", NULL);
rtree_insert_path(n, "/quux/bar/garply", NULL);
rtree_insert_path(n, "/quux/baz/foo", NULL);
rtree_insert_path(n, "/quux/baz/bar", NULL);
rtree_insert_path(n, "/quux/baz/qux", NULL);
rtree_insert_path(n, "/quux/baz/corge", NULL);
rtree_insert_path(n, "/quux/baz/grault", NULL);
rtree_insert_path(n, "/quux/baz/garply", NULL);
rtree_insert_path(n, "/quux/qux/foo", NULL);
rtree_insert_path(n, "/quux/qux/bar", NULL);
rtree_insert_path(n, "/quux/qux/baz", NULL);
rtree_insert_path(n, "/quux/qux/corge", NULL);
rtree_insert_path(n, "/quux/qux/grault", NULL);
rtree_insert_path(n, "/quux/qux/garply", NULL);
rtree_insert_path(n, "/quux/corge/foo", NULL);
rtree_insert_path(n, "/quux/corge/bar", NULL);
rtree_insert_path(n, "/quux/corge/baz", NULL);
rtree_insert_path(n, "/quux/corge/qux", NULL);
rtree_insert_path(n, "/quux/corge/grault", NULL);
rtree_insert_path(n, "/quux/corge/garply", NULL);
rtree_insert_path(n, "/quux/grault/foo", NULL);
rtree_insert_path(n, "/quux/grault/bar", NULL);
rtree_insert_path(n, "/quux/grault/baz", NULL);
rtree_insert_path(n, "/quux/grault/qux", NULL);
rtree_insert_path(n, "/quux/grault/corge", NULL);
rtree_insert_path(n, "/quux/grault/garply", NULL);
rtree_insert_path(n, "/quux/garply/foo", NULL);
rtree_insert_path(n, "/quux/garply/bar", NULL);
rtree_insert_path(n, "/quux/garply/baz", NULL);
rtree_insert_path(n, "/quux/garply/qux", NULL);
rtree_insert_path(n, "/quux/garply/corge", NULL);
rtree_insert_path(n, "/quux/garply/grault", NULL);
rtree_insert_path(n, "/corge/foo/bar", NULL);
rtree_insert_path(n, "/corge/foo/baz", NULL);
rtree_insert_path(n, "/corge/foo/qux", NULL);
rtree_insert_path(n, "/corge/foo/quux", NULL);
rtree_insert_path(n, "/corge/foo/grault", NULL);
rtree_insert_path(n, "/corge/foo/garply", NULL);
rtree_insert_path(n, "/corge/bar/foo", NULL);
rtree_insert_path(n, "/corge/bar/baz", NULL);
rtree_insert_path(n, "/corge/bar/qux", NULL);
rtree_insert_path(n, "/corge/bar/quux", NULL);
rtree_insert_path(n, "/corge/bar/grault", NULL);
rtree_insert_path(n, "/corge/bar/garply", NULL);
rtree_insert_path(n, "/corge/baz/foo", NULL);
rtree_insert_path(n, "/corge/baz/bar", NULL);
rtree_insert_path(n, "/corge/baz/qux", NULL);
rtree_insert_path(n, "/corge/baz/quux", NULL);
rtree_insert_path(n, "/corge/baz/grault", NULL);
rtree_insert_path(n, "/corge/baz/garply", NULL);
rtree_insert_path(n, "/corge/qux/foo", NULL);
rtree_insert_path(n, "/corge/qux/bar", NULL);
rtree_insert_path(n, "/corge/qux/baz", NULL);
rtree_insert_path(n, "/corge/qux/quux", NULL);
rtree_insert_path(n, "/corge/qux/grault", NULL);
rtree_insert_path(n, "/corge/qux/garply", NULL);
rtree_insert_path(n, "/corge/quux/foo", NULL);
rtree_insert_path(n, "/corge/quux/bar", NULL);
rtree_insert_path(n, "/corge/quux/baz", NULL);
rtree_insert_path(n, "/corge/quux/qux", NULL);
rtree_insert_path(n, "/corge/quux/grault", NULL);
rtree_insert_path(n, "/corge/quux/garply", NULL);
rtree_insert_path(n, "/corge/grault/foo", NULL);
rtree_insert_path(n, "/corge/grault/bar", NULL);
rtree_insert_path(n, "/corge/grault/baz", NULL);
rtree_insert_path(n, "/corge/grault/qux", NULL);
rtree_insert_path(n, "/corge/grault/quux", NULL);
rtree_insert_path(n, "/corge/grault/garply", NULL);
rtree_insert_path(n, "/corge/garply/foo", NULL);
rtree_insert_path(n, "/corge/garply/bar", NULL);
rtree_insert_path(n, "/corge/garply/baz", NULL);
rtree_insert_path(n, "/corge/garply/qux", NULL);
rtree_insert_path(n, "/corge/garply/quux", NULL);
rtree_insert_path(n, "/corge/garply/grault", NULL);
rtree_insert_path(n, "/grault/foo/bar", NULL);
rtree_insert_path(n, "/grault/foo/baz", NULL);
rtree_insert_path(n, "/grault/foo/qux", NULL);
rtree_insert_path(n, "/grault/foo/quux", NULL);
rtree_insert_path(n, "/grault/foo/corge", NULL);
rtree_insert_path(n, "/grault/foo/garply", NULL);
rtree_insert_path(n, "/grault/bar/foo", NULL);
rtree_insert_path(n, "/grault/bar/baz", NULL);
rtree_insert_path(n, "/grault/bar/qux", NULL);
rtree_insert_path(n, "/grault/bar/quux", NULL);
rtree_insert_path(n, "/grault/bar/corge", NULL);
rtree_insert_path(n, "/grault/bar/garply", NULL);
rtree_insert_path(n, "/grault/baz/foo", NULL);
rtree_insert_path(n, "/grault/baz/bar", NULL);
rtree_insert_path(n, "/grault/baz/qux", NULL);
rtree_insert_path(n, "/grault/baz/quux", NULL);
rtree_insert_path(n, "/grault/baz/corge", NULL);
rtree_insert_path(n, "/grault/baz/garply", NULL);
rtree_insert_path(n, "/grault/qux/foo", NULL);
rtree_insert_path(n, "/grault/qux/bar", NULL);
rtree_insert_path(n, "/grault/qux/baz", NULL);
rtree_insert_path(n, "/grault/qux/quux", NULL);
rtree_insert_path(n, "/grault/qux/corge", NULL);
rtree_insert_path(n, "/grault/qux/garply", NULL);
rtree_insert_path(n, "/grault/quux/foo", NULL);
rtree_insert_path(n, "/grault/quux/bar", NULL);
rtree_insert_path(n, "/grault/quux/baz", NULL);
rtree_insert_path(n, "/grault/quux/qux", NULL);
rtree_insert_path(n, "/grault/quux/corge", NULL);
rtree_insert_path(n, "/grault/quux/garply", NULL);
rtree_insert_path(n, "/grault/corge/foo", NULL);
rtree_insert_path(n, "/grault/corge/bar", NULL);
rtree_insert_path(n, "/grault/corge/baz", NULL);
rtree_insert_path(n, "/grault/corge/qux", NULL);
rtree_insert_path(n, "/grault/corge/quux", NULL);
rtree_insert_path(n, "/grault/corge/garply", NULL);
rtree_insert_path(n, "/grault/garply/foo", NULL);
rtree_insert_path(n, "/grault/garply/bar", NULL);
rtree_insert_path(n, "/grault/garply/baz", NULL);
rtree_insert_path(n, "/grault/garply/qux", NULL);
rtree_insert_path(n, "/grault/garply/quux", NULL);
rtree_insert_path(n, "/grault/garply/corge", NULL);
rtree_insert_path(n, "/garply/foo/bar", NULL);
rtree_insert_path(n, "/garply/foo/baz", NULL);
rtree_insert_path(n, "/garply/foo/qux", NULL);
rtree_insert_path(n, "/garply/foo/quux", NULL);
rtree_insert_path(n, "/garply/foo/corge", NULL);
rtree_insert_path(n, "/garply/foo/grault", NULL);
rtree_insert_path(n, "/garply/bar/foo", NULL);
rtree_insert_path(n, "/garply/bar/baz", NULL);
rtree_insert_path(n, "/garply/bar/qux", NULL);
rtree_insert_path(n, "/garply/bar/quux", NULL);
rtree_insert_path(n, "/garply/bar/corge", NULL);
rtree_insert_path(n, "/garply/bar/grault", NULL);
rtree_insert_path(n, "/garply/baz/foo", NULL);
rtree_insert_path(n, "/garply/baz/bar", NULL);
rtree_insert_path(n, "/garply/baz/qux", NULL);
rtree_insert_path(n, "/garply/baz/quux", NULL);
rtree_insert_path(n, "/garply/baz/corge", NULL);
rtree_insert_path(n, "/garply/baz/grault", NULL);
rtree_insert_path(n, "/garply/qux/foo", NULL);
rtree_insert_path(n, "/garply/qux/bar", NULL);
rtree_insert_path(n, "/garply/qux/baz", NULL);
rtree_insert_path(n, "/garply/qux/quux", NULL);
rtree_insert_path(n, "/garply/qux/corge", NULL);
rtree_insert_path(n, "/garply/qux/grault", NULL);
rtree_insert_path(n, "/garply/quux/foo", NULL);
rtree_insert_path(n, "/garply/quux/bar", NULL);
rtree_insert_path(n, "/garply/quux/baz", NULL);
rtree_insert_path(n, "/garply/quux/qux", NULL);
rtree_insert_path(n, "/garply/quux/corge", NULL);
rtree_insert_path(n, "/garply/quux/grault", NULL);
rtree_insert_path(n, "/garply/corge/foo", NULL);
rtree_insert_path(n, "/garply/corge/bar", NULL);
rtree_insert_path(n, "/garply/corge/baz", NULL);
rtree_insert_path(n, "/garply/corge/qux", NULL);
rtree_insert_path(n, "/garply/corge/quux", NULL);
rtree_insert_path(n, "/garply/corge/grault", NULL);
rtree_insert_path(n, "/garply/grault/foo", NULL);
rtree_insert_path(n, "/garply/grault/bar", NULL);
rtree_insert_path(n, "/garply/grault/baz", NULL);
rtree_insert_path(n, "/garply/grault/qux", NULL);
rtree_insert_path(n, "/garply/grault/quux", NULL);
rtree_insert_path(n, "/garply/grault/corge", NULL);
r3_tree_insert_path(n, "/foo/bar/baz", NULL);
r3_tree_insert_path(n, "/foo/bar/qux", NULL);
r3_tree_insert_path(n, "/foo/bar/quux", NULL);
r3_tree_insert_path(n, "/foo/bar/corge", NULL);
r3_tree_insert_path(n, "/foo/bar/grault", NULL);
r3_tree_insert_path(n, "/foo/bar/garply", NULL);
r3_tree_insert_path(n, "/foo/baz/bar", NULL);
r3_tree_insert_path(n, "/foo/baz/qux", NULL);
r3_tree_insert_path(n, "/foo/baz/quux", NULL);
r3_tree_insert_path(n, "/foo/baz/corge", NULL);
r3_tree_insert_path(n, "/foo/baz/grault", NULL);
r3_tree_insert_path(n, "/foo/baz/garply", NULL);
r3_tree_insert_path(n, "/foo/qux/bar", NULL);
r3_tree_insert_path(n, "/foo/qux/baz", NULL);
r3_tree_insert_path(n, "/foo/qux/quux", NULL);
r3_tree_insert_path(n, "/foo/qux/corge", NULL);
r3_tree_insert_path(n, "/foo/qux/grault", NULL);
r3_tree_insert_path(n, "/foo/qux/garply", NULL);
r3_tree_insert_path(n, "/foo/quux/bar", NULL);
r3_tree_insert_path(n, "/foo/quux/baz", NULL);
r3_tree_insert_path(n, "/foo/quux/qux", NULL);
r3_tree_insert_path(n, "/foo/quux/corge", NULL);
r3_tree_insert_path(n, "/foo/quux/grault", NULL);
r3_tree_insert_path(n, "/foo/quux/garply", NULL);
r3_tree_insert_path(n, "/foo/corge/bar", NULL);
r3_tree_insert_path(n, "/foo/corge/baz", NULL);
r3_tree_insert_path(n, "/foo/corge/qux", NULL);
r3_tree_insert_path(n, "/foo/corge/quux", NULL);
r3_tree_insert_path(n, "/foo/corge/grault", NULL);
r3_tree_insert_path(n, "/foo/corge/garply", NULL);
r3_tree_insert_path(n, "/foo/grault/bar", NULL);
r3_tree_insert_path(n, "/foo/grault/baz", NULL);
r3_tree_insert_path(n, "/foo/grault/qux", NULL);
r3_tree_insert_path(n, "/foo/grault/quux", NULL);
r3_tree_insert_path(n, "/foo/grault/corge", NULL);
r3_tree_insert_path(n, "/foo/grault/garply", NULL);
r3_tree_insert_path(n, "/foo/garply/bar", NULL);
r3_tree_insert_path(n, "/foo/garply/baz", NULL);
r3_tree_insert_path(n, "/foo/garply/qux", NULL);
r3_tree_insert_path(n, "/foo/garply/quux", NULL);
r3_tree_insert_path(n, "/foo/garply/corge", NULL);
r3_tree_insert_path(n, "/foo/garply/grault", NULL);
r3_tree_insert_path(n, "/bar/foo/baz", NULL);
r3_tree_insert_path(n, "/bar/foo/qux", NULL);
r3_tree_insert_path(n, "/bar/foo/quux", NULL);
r3_tree_insert_path(n, "/bar/foo/corge", NULL);
r3_tree_insert_path(n, "/bar/foo/grault", NULL);
r3_tree_insert_path(n, "/bar/foo/garply", NULL);
r3_tree_insert_path(n, "/bar/baz/foo", NULL);
r3_tree_insert_path(n, "/bar/baz/qux", NULL);
r3_tree_insert_path(n, "/bar/baz/quux", NULL);
r3_tree_insert_path(n, "/bar/baz/corge", NULL);
r3_tree_insert_path(n, "/bar/baz/grault", NULL);
r3_tree_insert_path(n, "/bar/baz/garply", NULL);
r3_tree_insert_path(n, "/bar/qux/foo", NULL);
r3_tree_insert_path(n, "/bar/qux/baz", NULL);
r3_tree_insert_path(n, "/bar/qux/quux", NULL);
r3_tree_insert_path(n, "/bar/qux/corge", NULL);
r3_tree_insert_path(n, "/bar/qux/grault", NULL);
r3_tree_insert_path(n, "/bar/qux/garply", NULL);
r3_tree_insert_path(n, "/bar/quux/foo", NULL);
r3_tree_insert_path(n, "/bar/quux/baz", NULL);
r3_tree_insert_path(n, "/bar/quux/qux", NULL);
r3_tree_insert_path(n, "/bar/quux/corge", NULL);
r3_tree_insert_path(n, "/bar/quux/grault", NULL);
r3_tree_insert_path(n, "/bar/quux/garply", NULL);
r3_tree_insert_path(n, "/bar/corge/foo", NULL);
r3_tree_insert_path(n, "/bar/corge/baz", NULL);
r3_tree_insert_path(n, "/bar/corge/qux", NULL);
r3_tree_insert_path(n, "/bar/corge/quux", NULL);
r3_tree_insert_path(n, "/bar/corge/grault", NULL);
r3_tree_insert_path(n, "/bar/corge/garply", NULL);
r3_tree_insert_path(n, "/bar/grault/foo", NULL);
r3_tree_insert_path(n, "/bar/grault/baz", NULL);
r3_tree_insert_path(n, "/bar/grault/qux", NULL);
r3_tree_insert_path(n, "/bar/grault/quux", NULL);
r3_tree_insert_path(n, "/bar/grault/corge", NULL);
r3_tree_insert_path(n, "/bar/grault/garply", NULL);
r3_tree_insert_path(n, "/bar/garply/foo", NULL);
r3_tree_insert_path(n, "/bar/garply/baz", NULL);
r3_tree_insert_path(n, "/bar/garply/qux", NULL);
r3_tree_insert_path(n, "/bar/garply/quux", NULL);
r3_tree_insert_path(n, "/bar/garply/corge", NULL);
r3_tree_insert_path(n, "/bar/garply/grault", NULL);
r3_tree_insert_path(n, "/baz/foo/bar", NULL);
r3_tree_insert_path(n, "/baz/foo/qux", NULL);
r3_tree_insert_path(n, "/baz/foo/quux", NULL);
r3_tree_insert_path(n, "/baz/foo/corge", NULL);
r3_tree_insert_path(n, "/baz/foo/grault", NULL);
r3_tree_insert_path(n, "/baz/foo/garply", NULL);
r3_tree_insert_path(n, "/baz/bar/foo", NULL);
r3_tree_insert_path(n, "/baz/bar/qux", NULL);
r3_tree_insert_path(n, "/baz/bar/quux", NULL);
r3_tree_insert_path(n, "/baz/bar/corge", NULL);
r3_tree_insert_path(n, "/baz/bar/grault", NULL);
r3_tree_insert_path(n, "/baz/bar/garply", NULL);
r3_tree_insert_path(n, "/baz/qux/foo", NULL);
r3_tree_insert_path(n, "/baz/qux/bar", NULL);
r3_tree_insert_path(n, "/baz/qux/quux", NULL);
r3_tree_insert_path(n, "/baz/qux/corge", NULL);
r3_tree_insert_path(n, "/baz/qux/grault", NULL);
r3_tree_insert_path(n, "/baz/qux/garply", NULL);
r3_tree_insert_path(n, "/baz/quux/foo", NULL);
r3_tree_insert_path(n, "/baz/quux/bar", NULL);
r3_tree_insert_path(n, "/baz/quux/qux", NULL);
r3_tree_insert_path(n, "/baz/quux/corge", NULL);
r3_tree_insert_path(n, "/baz/quux/grault", NULL);
r3_tree_insert_path(n, "/baz/quux/garply", NULL);
r3_tree_insert_path(n, "/baz/corge/foo", NULL);
r3_tree_insert_path(n, "/baz/corge/bar", NULL);
r3_tree_insert_path(n, "/baz/corge/qux", NULL);
r3_tree_insert_path(n, "/baz/corge/quux", NULL);
r3_tree_insert_path(n, "/baz/corge/grault", NULL);
r3_tree_insert_path(n, "/baz/corge/garply", NULL);
r3_tree_insert_path(n, "/baz/grault/foo", NULL);
r3_tree_insert_path(n, "/baz/grault/bar", NULL);
r3_tree_insert_path(n, "/baz/grault/qux", NULL);
r3_tree_insert_path(n, "/baz/grault/quux", NULL);
r3_tree_insert_path(n, "/baz/grault/corge", NULL);
r3_tree_insert_path(n, "/baz/grault/garply", NULL);
r3_tree_insert_path(n, "/baz/garply/foo", NULL);
r3_tree_insert_path(n, "/baz/garply/bar", NULL);
r3_tree_insert_path(n, "/baz/garply/qux", NULL);
r3_tree_insert_path(n, "/baz/garply/quux", NULL);
r3_tree_insert_path(n, "/baz/garply/corge", NULL);
r3_tree_insert_path(n, "/baz/garply/grault", NULL);
r3_tree_insert_path(n, "/qux/foo/bar", NULL);
r3_tree_insert_path(n, "/qux/foo/baz", NULL);
r3_tree_insert_path(n, "/qux/foo/quux", NULL);
r3_tree_insert_path(n, "/qux/foo/corge", NULL);
r3_tree_insert_path(n, "/qux/foo/grault", NULL);
r3_tree_insert_path(n, "/qux/foo/garply", NULL);
r3_tree_insert_path(n, "/qux/bar/foo", NULL);
r3_tree_insert_path(n, "/qux/bar/baz", NULL);
r3_tree_insert_path(n, "/qux/bar/quux", NULL);
r3_tree_insert_path(n, "/qux/bar/corge", (void*) 999);
r3_tree_insert_path(n, "/qux/bar/grault", NULL);
r3_tree_insert_path(n, "/qux/bar/garply", NULL);
r3_tree_insert_path(n, "/qux/baz/foo", NULL);
r3_tree_insert_path(n, "/qux/baz/bar", NULL);
r3_tree_insert_path(n, "/qux/baz/quux", NULL);
r3_tree_insert_path(n, "/qux/baz/corge", NULL);
r3_tree_insert_path(n, "/qux/baz/grault", NULL);
r3_tree_insert_path(n, "/qux/baz/garply", NULL);
r3_tree_insert_path(n, "/qux/quux/foo", NULL);
r3_tree_insert_path(n, "/qux/quux/bar", NULL);
r3_tree_insert_path(n, "/qux/quux/baz", NULL);
r3_tree_insert_path(n, "/qux/quux/corge", NULL);
r3_tree_insert_path(n, "/qux/quux/grault", NULL);
r3_tree_insert_path(n, "/qux/quux/garply", NULL);
r3_tree_insert_path(n, "/qux/corge/foo", NULL);
r3_tree_insert_path(n, "/qux/corge/bar", NULL);
r3_tree_insert_path(n, "/qux/corge/baz", NULL);
r3_tree_insert_path(n, "/qux/corge/quux", NULL);
r3_tree_insert_path(n, "/qux/corge/grault", NULL);
r3_tree_insert_path(n, "/qux/corge/garply", NULL);
r3_tree_insert_path(n, "/qux/grault/foo", NULL);
r3_tree_insert_path(n, "/qux/grault/bar", NULL);
r3_tree_insert_path(n, "/qux/grault/baz", NULL);
r3_tree_insert_path(n, "/qux/grault/quux", NULL);
r3_tree_insert_path(n, "/qux/grault/corge", NULL);
r3_tree_insert_path(n, "/qux/grault/garply", NULL);
r3_tree_insert_path(n, "/qux/garply/foo", NULL);
r3_tree_insert_path(n, "/qux/garply/bar", NULL);
r3_tree_insert_path(n, "/qux/garply/baz", NULL);
r3_tree_insert_path(n, "/qux/garply/quux", NULL);
r3_tree_insert_path(n, "/qux/garply/corge", NULL);
r3_tree_insert_path(n, "/qux/garply/grault", NULL);
r3_tree_insert_path(n, "/quux/foo/bar", NULL);
r3_tree_insert_path(n, "/quux/foo/baz", NULL);
r3_tree_insert_path(n, "/quux/foo/qux", NULL);
r3_tree_insert_path(n, "/quux/foo/corge", NULL);
r3_tree_insert_path(n, "/quux/foo/grault", NULL);
r3_tree_insert_path(n, "/quux/foo/garply", NULL);
r3_tree_insert_path(n, "/quux/bar/foo", NULL);
r3_tree_insert_path(n, "/quux/bar/baz", NULL);
r3_tree_insert_path(n, "/quux/bar/qux", NULL);
r3_tree_insert_path(n, "/quux/bar/corge", NULL);
r3_tree_insert_path(n, "/quux/bar/grault", NULL);
r3_tree_insert_path(n, "/quux/bar/garply", NULL);
r3_tree_insert_path(n, "/quux/baz/foo", NULL);
r3_tree_insert_path(n, "/quux/baz/bar", NULL);
r3_tree_insert_path(n, "/quux/baz/qux", NULL);
r3_tree_insert_path(n, "/quux/baz/corge", NULL);
r3_tree_insert_path(n, "/quux/baz/grault", NULL);
r3_tree_insert_path(n, "/quux/baz/garply", NULL);
r3_tree_insert_path(n, "/quux/qux/foo", NULL);
r3_tree_insert_path(n, "/quux/qux/bar", NULL);
r3_tree_insert_path(n, "/quux/qux/baz", NULL);
r3_tree_insert_path(n, "/quux/qux/corge", NULL);
r3_tree_insert_path(n, "/quux/qux/grault", NULL);
r3_tree_insert_path(n, "/quux/qux/garply", NULL);
r3_tree_insert_path(n, "/quux/corge/foo", NULL);
r3_tree_insert_path(n, "/quux/corge/bar", NULL);
r3_tree_insert_path(n, "/quux/corge/baz", NULL);
r3_tree_insert_path(n, "/quux/corge/qux", NULL);
r3_tree_insert_path(n, "/quux/corge/grault", NULL);
r3_tree_insert_path(n, "/quux/corge/garply", NULL);
r3_tree_insert_path(n, "/quux/grault/foo", NULL);
r3_tree_insert_path(n, "/quux/grault/bar", NULL);
r3_tree_insert_path(n, "/quux/grault/baz", NULL);
r3_tree_insert_path(n, "/quux/grault/qux", NULL);
r3_tree_insert_path(n, "/quux/grault/corge", NULL);
r3_tree_insert_path(n, "/quux/grault/garply", NULL);
r3_tree_insert_path(n, "/quux/garply/foo", NULL);
r3_tree_insert_path(n, "/quux/garply/bar", NULL);
r3_tree_insert_path(n, "/quux/garply/baz", NULL);
r3_tree_insert_path(n, "/quux/garply/qux", NULL);
r3_tree_insert_path(n, "/quux/garply/corge", NULL);
r3_tree_insert_path(n, "/quux/garply/grault", NULL);
r3_tree_insert_path(n, "/corge/foo/bar", NULL);
r3_tree_insert_path(n, "/corge/foo/baz", NULL);
r3_tree_insert_path(n, "/corge/foo/qux", NULL);
r3_tree_insert_path(n, "/corge/foo/quux", NULL);
r3_tree_insert_path(n, "/corge/foo/grault", NULL);
r3_tree_insert_path(n, "/corge/foo/garply", NULL);
r3_tree_insert_path(n, "/corge/bar/foo", NULL);
r3_tree_insert_path(n, "/corge/bar/baz", NULL);
r3_tree_insert_path(n, "/corge/bar/qux", NULL);
r3_tree_insert_path(n, "/corge/bar/quux", NULL);
r3_tree_insert_path(n, "/corge/bar/grault", NULL);
r3_tree_insert_path(n, "/corge/bar/garply", NULL);
r3_tree_insert_path(n, "/corge/baz/foo", NULL);
r3_tree_insert_path(n, "/corge/baz/bar", NULL);
r3_tree_insert_path(n, "/corge/baz/qux", NULL);
r3_tree_insert_path(n, "/corge/baz/quux", NULL);
r3_tree_insert_path(n, "/corge/baz/grault", NULL);
r3_tree_insert_path(n, "/corge/baz/garply", NULL);
r3_tree_insert_path(n, "/corge/qux/foo", NULL);
r3_tree_insert_path(n, "/corge/qux/bar", NULL);
r3_tree_insert_path(n, "/corge/qux/baz", NULL);
r3_tree_insert_path(n, "/corge/qux/quux", NULL);
r3_tree_insert_path(n, "/corge/qux/grault", NULL);
r3_tree_insert_path(n, "/corge/qux/garply", NULL);
r3_tree_insert_path(n, "/corge/quux/foo", NULL);
r3_tree_insert_path(n, "/corge/quux/bar", NULL);
r3_tree_insert_path(n, "/corge/quux/baz", NULL);
r3_tree_insert_path(n, "/corge/quux/qux", NULL);
r3_tree_insert_path(n, "/corge/quux/grault", NULL);
r3_tree_insert_path(n, "/corge/quux/garply", NULL);
r3_tree_insert_path(n, "/corge/grault/foo", NULL);
r3_tree_insert_path(n, "/corge/grault/bar", NULL);
r3_tree_insert_path(n, "/corge/grault/baz", NULL);
r3_tree_insert_path(n, "/corge/grault/qux", NULL);
r3_tree_insert_path(n, "/corge/grault/quux", NULL);
r3_tree_insert_path(n, "/corge/grault/garply", NULL);
r3_tree_insert_path(n, "/corge/garply/foo", NULL);
r3_tree_insert_path(n, "/corge/garply/bar", NULL);
r3_tree_insert_path(n, "/corge/garply/baz", NULL);
r3_tree_insert_path(n, "/corge/garply/qux", NULL);
r3_tree_insert_path(n, "/corge/garply/quux", NULL);
r3_tree_insert_path(n, "/corge/garply/grault", NULL);
r3_tree_insert_path(n, "/grault/foo/bar", NULL);
r3_tree_insert_path(n, "/grault/foo/baz", NULL);
r3_tree_insert_path(n, "/grault/foo/qux", NULL);
r3_tree_insert_path(n, "/grault/foo/quux", NULL);
r3_tree_insert_path(n, "/grault/foo/corge", NULL);
r3_tree_insert_path(n, "/grault/foo/garply", NULL);
r3_tree_insert_path(n, "/grault/bar/foo", NULL);
r3_tree_insert_path(n, "/grault/bar/baz", NULL);
r3_tree_insert_path(n, "/grault/bar/qux", NULL);
r3_tree_insert_path(n, "/grault/bar/quux", NULL);
r3_tree_insert_path(n, "/grault/bar/corge", NULL);
r3_tree_insert_path(n, "/grault/bar/garply", NULL);
r3_tree_insert_path(n, "/grault/baz/foo", NULL);
r3_tree_insert_path(n, "/grault/baz/bar", NULL);
r3_tree_insert_path(n, "/grault/baz/qux", NULL);
r3_tree_insert_path(n, "/grault/baz/quux", NULL);
r3_tree_insert_path(n, "/grault/baz/corge", NULL);
r3_tree_insert_path(n, "/grault/baz/garply", NULL);
r3_tree_insert_path(n, "/grault/qux/foo", NULL);
r3_tree_insert_path(n, "/grault/qux/bar", NULL);
r3_tree_insert_path(n, "/grault/qux/baz", NULL);
r3_tree_insert_path(n, "/grault/qux/quux", NULL);
r3_tree_insert_path(n, "/grault/qux/corge", NULL);
r3_tree_insert_path(n, "/grault/qux/garply", NULL);
r3_tree_insert_path(n, "/grault/quux/foo", NULL);
r3_tree_insert_path(n, "/grault/quux/bar", NULL);
r3_tree_insert_path(n, "/grault/quux/baz", NULL);
r3_tree_insert_path(n, "/grault/quux/qux", NULL);
r3_tree_insert_path(n, "/grault/quux/corge", NULL);
r3_tree_insert_path(n, "/grault/quux/garply", NULL);
r3_tree_insert_path(n, "/grault/corge/foo", NULL);
r3_tree_insert_path(n, "/grault/corge/bar", NULL);
r3_tree_insert_path(n, "/grault/corge/baz", NULL);
r3_tree_insert_path(n, "/grault/corge/qux", NULL);
r3_tree_insert_path(n, "/grault/corge/quux", NULL);
r3_tree_insert_path(n, "/grault/corge/garply", NULL);
r3_tree_insert_path(n, "/grault/garply/foo", NULL);
r3_tree_insert_path(n, "/grault/garply/bar", NULL);
r3_tree_insert_path(n, "/grault/garply/baz", NULL);
r3_tree_insert_path(n, "/grault/garply/qux", NULL);
r3_tree_insert_path(n, "/grault/garply/quux", NULL);
r3_tree_insert_path(n, "/grault/garply/corge", NULL);
r3_tree_insert_path(n, "/garply/foo/bar", NULL);
r3_tree_insert_path(n, "/garply/foo/baz", NULL);
r3_tree_insert_path(n, "/garply/foo/qux", NULL);
r3_tree_insert_path(n, "/garply/foo/quux", NULL);
r3_tree_insert_path(n, "/garply/foo/corge", NULL);
r3_tree_insert_path(n, "/garply/foo/grault", NULL);
r3_tree_insert_path(n, "/garply/bar/foo", NULL);
r3_tree_insert_path(n, "/garply/bar/baz", NULL);
r3_tree_insert_path(n, "/garply/bar/qux", NULL);
r3_tree_insert_path(n, "/garply/bar/quux", NULL);
r3_tree_insert_path(n, "/garply/bar/corge", NULL);
r3_tree_insert_path(n, "/garply/bar/grault", NULL);
r3_tree_insert_path(n, "/garply/baz/foo", NULL);
r3_tree_insert_path(n, "/garply/baz/bar", NULL);
r3_tree_insert_path(n, "/garply/baz/qux", NULL);
r3_tree_insert_path(n, "/garply/baz/quux", NULL);
r3_tree_insert_path(n, "/garply/baz/corge", NULL);
r3_tree_insert_path(n, "/garply/baz/grault", NULL);
r3_tree_insert_path(n, "/garply/qux/foo", NULL);
r3_tree_insert_path(n, "/garply/qux/bar", NULL);
r3_tree_insert_path(n, "/garply/qux/baz", NULL);
r3_tree_insert_path(n, "/garply/qux/quux", NULL);
r3_tree_insert_path(n, "/garply/qux/corge", NULL);
r3_tree_insert_path(n, "/garply/qux/grault", NULL);
r3_tree_insert_path(n, "/garply/quux/foo", NULL);
r3_tree_insert_path(n, "/garply/quux/bar", NULL);
r3_tree_insert_path(n, "/garply/quux/baz", NULL);
r3_tree_insert_path(n, "/garply/quux/qux", NULL);
r3_tree_insert_path(n, "/garply/quux/corge", NULL);
r3_tree_insert_path(n, "/garply/quux/grault", NULL);
r3_tree_insert_path(n, "/garply/corge/foo", NULL);
r3_tree_insert_path(n, "/garply/corge/bar", NULL);
r3_tree_insert_path(n, "/garply/corge/baz", NULL);
r3_tree_insert_path(n, "/garply/corge/qux", NULL);
r3_tree_insert_path(n, "/garply/corge/quux", NULL);
r3_tree_insert_path(n, "/garply/corge/grault", NULL);
r3_tree_insert_path(n, "/garply/grault/foo", NULL);
r3_tree_insert_path(n, "/garply/grault/bar", NULL);
r3_tree_insert_path(n, "/garply/grault/baz", NULL);
r3_tree_insert_path(n, "/garply/grault/qux", NULL);
r3_tree_insert_path(n, "/garply/grault/quux", NULL);
r3_tree_insert_path(n, "/garply/grault/corge", NULL);
rtree_compile(n);
// rtree_dump(n, 0);
r3_tree_compile(n);
// r3_tree_dump(n, 0);
// match_entry *entry = calloc( sizeof(entry) , 1 );
node *m;
m = rtree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
m = r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
fail_if( m == NULL );
// rtree_dump( m, 0 );
// r3_tree_dump( m, 0 );
ck_assert_int_eq( (int) m->route_ptr, 999 );
@ -638,7 +638,7 @@ START_TEST(benchmark_str)
double s = microtime();
long N = 5000000;
for (int i = 0; i < 5000000 ; i++ ) {
rtree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
}
double e = microtime();
@ -660,9 +660,9 @@ Suite* r3_suite (void) {
tcase_add_test(tcase, test_route_split);
tcase_add_test(tcase, test_str_array);
tcase_add_test(tcase, test_ltrim_slash);
tcase_add_test(tcase, test_node_construct_uniq);
tcase_add_test(tcase, test_node_find_edge);
tcase_add_test(tcase, test_rtree_insert_pathn);
tcase_add_test(tcase, test_r3_node_construct_uniq);
tcase_add_test(tcase, test_r3_node_find_edge);
tcase_add_test(tcase, test_r3_tree_insert_pathn);
tcase_add_test(tcase, test_compile_slug);
tcase_add_test(tcase, test_compile);