function name fix

This commit is contained in:
c9s 2014-05-21 00:47:09 +08:00
parent cae305b92d
commit 5bd1757e5f
6 changed files with 18 additions and 19 deletions

View file

@ -10,7 +10,7 @@ API changes:
r3_tree_insert_path(n, "/user2/{id:\\d+}", &var2); r3_tree_insert_path(n, "/user2/{id:\\d+}", &var2);
2. The original `r3_tree_insert_pathl_` has been moved to `_r3_tree_insert_pathl_` as a private API. 2. The original `r3_tree_insert_pathl_` has been moved to `r3_tree_insert_pathl_` as a private API.
3. Moved `r3_tree_matchl` to `r3_tree_matchl` since it require the length of the path string. 3. Moved `r3_tree_matchl` to `r3_tree_matchl` since it require the length of the path string.

View file

@ -43,12 +43,12 @@ int route_data = 3;
// insert the route path into the router tree // insert the route path into the router tree
r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path r3_tree_insert_path(n, "/bar", &route_data); // ignore the length of path
r3_tree_insert_pathl_(n, "/zoo", strlen("/zoo"), &route_data ); r3_tree_insert_pathl(n, "/zoo", strlen("/zoo"), &route_data );
r3_tree_insert_pathl_(n, "/foo/bar", strlen("/foo/bar"), &route_data ); r3_tree_insert_pathl(n, "/foo/bar", strlen("/foo/bar"), &route_data );
r3_tree_insert_pathl_(n ,"/post/{id}", strlen("/post/{id}") , &route_data ); r3_tree_insert_pathl(n ,"/post/{id}", strlen("/post/{id}") , &route_data );
r3_tree_insert_pathl_(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), &route_data ); r3_tree_insert_pathl(n, "/user/{id:\\d+}", strlen("/user/{id:\\d+}"), &route_data );
// let's compile the tree! // let's compile the tree!
r3_tree_compile(n); r3_tree_compile(n);

View file

@ -108,17 +108,15 @@ edge * r3_node_find_edge(node * n, char * pat);
void r3_node_append_edge(node *n, edge *child); void r3_node_append_edge(node *n, edge *child);
node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, void * data); node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data);
#define r3_tree_insert_path(n,p,d) _r3_tree_insert_pathl_(n,p,strlen(p), NULL, d) #define r3_tree_insert_path(n,p,d) r3_tree_insert_pathl_(n,p,strlen(p), NULL, d)
#define r3_tree_insert_route(n,r,d) r3_tree_insert_pathl_(n, r->path, r->path_len, r, d)
// node * r3_tree_insert_route(node *tree, route * route, void * data);
#define r3_tree_insert_route(n,r,d) _r3_tree_insert_pathl_(n, r->path, r->path_len, r, d)
/** /**
* The private API to insert a path * The private API to insert a path
*/ */
node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data); node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data);
void r3_tree_dump(node * n, int level); void r3_tree_dump(node * n, int level);

View file

@ -403,16 +403,16 @@ route * r3_route_createl(char * path, int path_len) {
return info; return info;
} }
node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, void * data) node * r3_tree_insert_pathl(node *tree, char *path, int path_len, void * data)
{ {
return _r3_tree_insert_pathl_(tree, path, path_len, NULL , data); return r3_tree_insert_pathl_(tree, path, path_len, NULL , data);
} }
/** /**
* Return the last inserted node. * Return the last inserted node.
*/ */
node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data) node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route, void * data)
{ {
node * n = tree; node * n = tree;
edge * e = NULL; edge * e = NULL;
@ -461,7 +461,7 @@ node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * rout
r3_node_add_child(n, strndup(path, (int)(p - path)), child); r3_node_add_child(n, strndup(path, (int)(p - path)), child);
// and insert the rest part to the child // and insert the rest part to the child
return _r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data); return r3_tree_insert_pathl_(child, p, path_len - (int)(p - path), route, data);
} else { } else {
node * child = r3_tree_create(3); node * child = r3_tree_create(3);
r3_node_add_child(n, strndup(path, path_len) , child); r3_node_add_child(n, strndup(path, path_len) , child);
@ -482,7 +482,7 @@ node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * rout
// there are something more we can insert // there are something more we can insert
if ( subpath_len > 0 ) { if ( subpath_len > 0 ) {
return _r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data); return r3_tree_insert_pathl_(e->child, subpath, subpath_len, route, data);
} else { } else {
// there are no more path to insert // there are no more path to insert
@ -510,7 +510,7 @@ node * _r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * rout
char * s2 = path + prefix_len; char * s2 = path + prefix_len;
int s2_len = path_len - prefix_len; int s2_len = path_len - prefix_len;
r3_edge_branch(e, prefix_len); r3_edge_branch(e, prefix_len);
return _r3_tree_insert_pathl_(e->child, s2 , s2_len, route , data); return r3_tree_insert_pathl_(e->child, s2 , s2_len, route , data);
} else { } else {
printf("unexpected route."); printf("unexpected route.");
return NULL; return NULL;

View file

@ -397,3 +397,4 @@
1400603778,13736212.66 1400603778,13736212.66
1400603800,13715365.00 1400603800,13715365.00
1400603827,12742770.05 1400603827,12742770.05
1400604427,13725403.62

1 1400242718 5649455.80
397 1400603778 13736212.66
398 1400603800 13715365.00
399 1400603827 12742770.05
400 1400604427 13725403.62

View file

@ -159,7 +159,7 @@ END_TEST
START_TEST (test_r3_tree_insert_pathl_) START_TEST (testr3_tree_insert_pathl)
{ {
node * n = r3_tree_create(10); node * n = r3_tree_create(10);
@ -717,7 +717,7 @@ Suite* r3_suite (void) {
tcase_add_test(tcase, test_str_array); tcase_add_test(tcase, test_str_array);
tcase_add_test(tcase, test_ltrim_slash); tcase_add_test(tcase, test_ltrim_slash);
tcase_add_test(tcase, test_r3_node_find_edge); tcase_add_test(tcase, test_r3_node_find_edge);
tcase_add_test(tcase, test_r3_tree_insert_pathl_); tcase_add_test(tcase, testr3_tree_insert_pathl);
tcase_add_test(tcase, test_compile); tcase_add_test(tcase, test_compile);
tcase_add_test(tcase, test_route_cmp); tcase_add_test(tcase, test_route_cmp);
tcase_add_test(tcase, test_insert_route); tcase_add_test(tcase, test_insert_route);