setting up parent and child.
This commit is contained in:
parent
24aaa881b1
commit
ba270b5948
4 changed files with 17 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -62,6 +63,8 @@ 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;
|
||||
|
||||
/* 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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -445,3 +445,5 @@
|
|||
1400685490,13185955.87
|
||||
1400748100,12609470.07
|
||||
1400748288,13317009.48
|
||||
1400748727,12973679.22
|
||||
1400748826,12902583.84
|
||||
|
|
|
Loading…
Reference in a new issue