Skip to content

Commit

Permalink
Rename route_ptr => route
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 18, 2014
1 parent 5ca345d commit 64acfd8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
12 changes: 7 additions & 5 deletions include/r3.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ struct _node {
int * ov;

/**
* the pointer of route structure
* the pointer of route data
*/
void * route_ptr;
void * data;

int endpoint;
};
Expand All @@ -60,8 +60,10 @@ typedef struct {
str_array * vars;
char * path; // current path to dispatch
int path_len; // the length of the current path
void * route_ptr; // route ptr
int request_method; // current request method

void * data; // route ptr

char * host; // the request host
int host_len;

Expand Down Expand Up @@ -98,9 +100,9 @@ edge * r3_node_find_edge(node * n, char * pat);

void r3_tree_append_edge(node *n, edge *child);

node * r3_tree_insert_path(node *tree, char *route, void * route_ptr);
node * r3_tree_insert_path(node *tree, char *route, void * data);

node * r3_tree_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 * data);

void r3_tree_dump(node * n, int level);

Expand Down
16 changes: 8 additions & 8 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ match_entry * match_entry_createl(char * path, int path_len) {
entry->vars = str_array_create(3);
entry->path = path;
entry->path_len = path_len;
entry->route_ptr = NULL;
entry->data = NULL;
return entry;
}

Expand Down Expand Up @@ -364,12 +364,12 @@ node * r3_node_create() {
}


node * r3_tree_insert_path(node *tree, char *route, void * route_ptr)
node * r3_tree_insert_path(node *tree, char *route, void * data)
{
return r3_tree_insert_pathn(tree, route, strlen(route) , route_ptr);
return r3_tree_insert_pathn(tree, route, strlen(route) , data);
}

node * r3_tree_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 * data)
{
node * n = tree;
edge * e = NULL;
Expand Down Expand Up @@ -403,7 +403,7 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route
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->data = data;
child->endpoint++;
return child;
} else if ( offset == e->pattern_len ) { // fully-equal to the pattern of the edge
Expand All @@ -413,11 +413,11 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route

// there are something more we can insert
if ( subroute_len > 0 ) {
return r3_tree_insert_pathn(e->child, subroute, subroute_len, route_ptr);
return r3_tree_insert_pathn(e->child, subroute, subroute_len, data);
} else {
// no more,
e->child->endpoint++; // make it as an endpoint, TODO: put the route value
e->child->route_ptr = route_ptr;
e->child->data = data;
return e->child;
}

Expand Down Expand Up @@ -451,7 +451,7 @@ node * r3_tree_insert_pathn(node *tree, char *route, int route_len, void * route

// move n->edges to c1
c2->endpoint++;
c2->route_ptr = route_ptr;
c2->data = data;
return c2;
} else {
printf("unexpected condition.");
Expand Down
1 change: 1 addition & 0 deletions tests/bench_str.csv
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@
1400374415,13164892.40
1400382244,12226293.04
1400382299,11775631.24
1400382382,12331702.88
2 changes: 1 addition & 1 deletion tests/check_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ START_TEST(benchmark_str)
m = r3_tree_match(n , "/qux/bar/corge", strlen("/qux/bar/corge"), NULL);
fail_if( m == NULL );
// r3_tree_dump( m, 0 );
ck_assert_int_eq( *((int*) m->route_ptr), 999 );
ck_assert_int_eq( *((int*) m->data), 999 );


printf("Benchmarking...\n");
Expand Down

0 comments on commit 64acfd8

Please sign in to comment.