_r3_tree_insert_pathl to r3_tree_insert_pathl_
This commit is contained in:
parent
02b4008a69
commit
750a9beaa4
5 changed files with 19 additions and 19 deletions
|
@ -2,15 +2,15 @@
|
|||
|
||||
API changes:
|
||||
|
||||
1. Removed the `route` argument from `r3_tree_insert_pathl`:
|
||||
1. Removed the `route` argument from `r3_tree_insert_pathl_`:
|
||||
|
||||
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);
|
||||
|
||||
This reduce the interface complexity, e.g.,
|
||||
|
||||
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.
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ int route_data = 3;
|
|||
// insert the route path into the router tree
|
||||
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, "/foo/bar", strlen("/foo/bar"), &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 ,"/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!
|
||||
r3_tree_compile(n);
|
||||
|
|
|
@ -106,17 +106,17 @@ edge * r3_node_find_edge(node * n, char * pat);
|
|||
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)
|
||||
|
||||
// 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)
|
||||
#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
|
||||
*/
|
||||
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);
|
||||
|
||||
|
|
12
src/node.c
12
src/node.c
|
@ -403,16 +403,16 @@ route * r3_route_createl(char * path, int path_len) {
|
|||
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.
|
||||
*/
|
||||
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;
|
||||
edge * e = NULL;
|
||||
|
@ -461,7 +461,7 @@ node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route
|
|||
r3_node_add_child(n, strndup(path, (int)(p - path)), 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 {
|
||||
node * child = r3_tree_create(3);
|
||||
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 * route
|
|||
|
||||
// there are something more we can insert
|
||||
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 {
|
||||
// there are no more path to insert
|
||||
|
||||
|
@ -510,7 +510,7 @@ node * _r3_tree_insert_pathl(node *tree, char *path, int path_len, route * route
|
|||
char * s2 = path + prefix_len;
|
||||
int s2_len = path_len - 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 {
|
||||
printf("unexpected route.");
|
||||
return NULL;
|
||||
|
|
|
@ -155,7 +155,7 @@ END_TEST
|
|||
|
||||
|
||||
|
||||
START_TEST (test_r3_tree_insert_pathl)
|
||||
START_TEST (test_r3_tree_insert_pathl_)
|
||||
{
|
||||
node * n = r3_tree_create(10);
|
||||
|
||||
|
@ -713,7 +713,7 @@ Suite* r3_suite (void) {
|
|||
tcase_add_test(tcase, test_str_array);
|
||||
tcase_add_test(tcase, test_ltrim_slash);
|
||||
tcase_add_test(tcase, test_r3_node_find_edge);
|
||||
tcase_add_test(tcase, test_r3_tree_insert_pathl);
|
||||
tcase_add_test(tcase, test_r3_tree_insert_pathl_);
|
||||
tcase_add_test(tcase, test_compile);
|
||||
tcase_add_test(tcase, test_route_cmp);
|
||||
tcase_add_test(tcase, test_insert_route);
|
||||
|
|
Loading…
Reference in a new issue