setting up parent and child.

This commit is contained in:
c9s 2014-05-22 16:53:52 +08:00
parent 24aaa881b1
commit ba270b5948
4 changed files with 17 additions and 2 deletions

View file

@ -66,7 +66,11 @@ struct _node {
struct _edge {
char * pattern;
int pattern_len;
/* the child node */
node * child;
/* the parent node */
node * parent;
uint64_t hits;
float score;
bool has_slug:1;

View file

@ -29,6 +29,7 @@ edge * r3_edge_create(char * pattern, int pattern_len, node * child) {
e->pattern = pattern;
e->pattern_len = pattern_len;
e->child = child;
e->parent = NULL;
// update childs parent edge
child->parent_edge = e;
@ -61,8 +62,10 @@ node * r3_edge_branch(edge *e, int dl) {
// the suffix edge of the leaf
new_child = r3_tree_create(3);
s1_len = e->pattern_len - dl;
e1 = r3_edge_create(zstrndup(s1, s1_len), s1_len, new_child);
s1_len = e->pattern_len - dl;
/* create the parent edge of 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.
for ( int i = 0 ; i < tmp_edge_len ; i++ ) {

View file

@ -129,6 +129,8 @@ void r3_node_append_edge(node *n, edge *e) {
n->edges = p;
}
}
// when append new edge, we update the parent node of the edge.
e->parent = n;
n->edges[ n->edge_len++ ] = e;
}
@ -557,6 +559,10 @@ void r3_tree_dump(node * n, int level) {
printf(" regexp:%s", n->combined_pattern);
}
if ( n->parent_edge ) {
printf(" belongs to edge:%p", n->parent_edge);
}
printf(" endpoint:%d", n->endpoint);
if (n->data) {

View file

@ -445,3 +445,5 @@
1400685490,13185955.87
1400748100,12609470.07
1400748288,13317009.48
1400748727,12973679.22
1400748826,12902583.84

1 1400242718 5649455.80
445 1400685490 13185955.87
446 1400748100 12609470.07
447 1400748288 13317009.48
448 1400748727 12973679.22
449 1400748826 12902583.84