edge branch with routes and other resets

This commit is contained in:
c9s 2014-05-27 14:16:42 +08:00
parent 60821aac0c
commit cf734a480c
2 changed files with 16 additions and 6 deletions

View file

@ -54,6 +54,7 @@ typedef struct _route route;
struct _node { struct _node {
edge ** edges; edge ** edges;
// edge ** edge_table;
// almost less than 255 // almost less than 255
unsigned char edge_len; unsigned char edge_len;

View file

@ -49,27 +49,36 @@ node * r3_edge_branch(edge *e, int dl) {
char * s1 = e->pattern + dl; char * s1 = e->pattern + dl;
int s1_len = 0; int s1_len = 0;
edge **tmp_edges = e->child->edges;
int tmp_edge_len = e->child->edge_len;
// the suffix edge of the leaf // the suffix edge of the leaf
new_child = r3_tree_create(3); new_child = r3_tree_create(3);
s1_len = e->pattern_len - dl; s1_len = e->pattern_len - dl;
e1 = r3_edge_create(zstrndup(s1, s1_len), s1_len, new_child); e1 = r3_edge_create(zstrndup(s1, s1_len), s1_len, new_child);
// Migrate the child edges to the new edge we just created. // Migrate the child edges to the new edge we just created.
for ( int i = 0 ; i < tmp_edge_len ; i++ ) { for ( int i = 0 ; i < e->child->edge_len ; i++ ) {
r3_node_append_edge(new_child, tmp_edges[i]); r3_node_append_edge(new_child, e->child->edges[i]);
e->child->edges[i] = NULL; e->child->edges[i] = NULL;
} }
e->child->edge_len = 0; e->child->edge_len = 0;
// Migrate the child routes
for ( int i = 0 ; i < e->child->route_len ; i++ ) {
r3_node_append_route(new_child, e->child->routes[i]);
e->child->routes[i] = NULL;
}
e->child->route_len = 0;
// Migrate the endpoint
new_child->endpoint = e->child->endpoint; new_child->endpoint = e->child->endpoint;
e->child->endpoint = 0; // reset endpoint e->child->endpoint = 0; // reset endpoint
r3_node_append_edge(e->child, e1); // Migrate the data
new_child->data = e->child->data; // copy data pointer new_child->data = e->child->data; // copy data pointer
e->child->data = NULL; e->child->data = NULL;
r3_node_append_edge(e->child, e1);
// truncate the original edge pattern // truncate the original edge pattern
char *oldpattern = e->pattern; char *oldpattern = e->pattern;
e->pattern = zstrndup(e->pattern, dl); e->pattern = zstrndup(e->pattern, dl);