From 64acfd8cd6384e191b9d29d923360feddcd17934 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 18 May 2014 11:06:24 +0800 Subject: [PATCH] Rename route_ptr => route --- include/r3.h | 12 +++++++----- src/node.c | 16 ++++++++-------- tests/bench_str.csv | 1 + tests/check_tree.c | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/r3.h b/include/r3.h index f303094..40b3fd9 100644 --- a/include/r3.h +++ b/include/r3.h @@ -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; }; @@ -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; @@ -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); diff --git a/src/node.c b/src/node.c index 4caa63f..b5a03d2 100644 --- a/src/node.c +++ b/src/node.c @@ -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; } @@ -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; @@ -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 @@ -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; } @@ -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."); diff --git a/tests/bench_str.csv b/tests/bench_str.csv index 5e20d40..8322e57 100644 --- a/tests/bench_str.csv +++ b/tests/bench_str.csv @@ -88,3 +88,4 @@ 1400374415,13164892.40 1400382244,12226293.04 1400382299,11775631.24 +1400382382,12331702.88 diff --git a/tests/check_tree.c b/tests/check_tree.c index 1caf5a6..df1436e 100644 --- a/tests/check_tree.c +++ b/tests/check_tree.c @@ -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");