Add a new child to the node 'n' representing the character 'c' and return * its new pointer, as well as the child pointer by reference. Additionally * '***parentlink' is populated with the raxNode pointer-to-pointer of where * the new child was stored, which is useful for the caller to replace the * child pointer if it gets reallocated. * * On success the new parent node pointer is returned
| 463 | * of the realloc, so the caller should discard 'n' and use the new value). |
| 464 | * On out of memory NULL is returned, and the old node is still valid. */ |
| 465 | raxNode *raxAddChild(rax *rax, raxNode *n, unsigned char c, raxNode **childptr, raxNode ***parentlink) { |
| 466 | /* Alloc the new child we will link to 'n'. */ |
| 467 | raxNode *child = raxNewNode(0,0); |
| 468 | if (child == NULL) return NULL; |
| 469 | |
| 470 | raxNode *newn = raxAddChildNoAlloc(rax,n,c,parentlink); |
| 471 | if (newn == NULL) { |
| 472 | rax_free(child); |
| 473 | return NULL; |
| 474 | } |
| 475 | memcpy(*parentlink,&child,sizeof(child)); |
| 476 | *childptr = child; |
| 477 | return newn; |
| 478 | } |
| 479 | |
| 480 | /* Turn the node 'n', that must be a node without any children, into a |
| 481 | * compressed node representing a set of nodes linked one after the other |
no test coverage detected