11.6 Copying [ToC] [Index]     [Skip Back] [Skip Fwd]     [Prev] [Up] [Next]

We can reuse most of the RTBST copying functionality for copying RTAVL trees, but we must modify the node copy function to copy the balance factor into the new node as well.

449. <RTAVL copy function 449> =
<RTAVL node copy function 450>
<RTBST copy error helper function; rtbst => rtavl 407>
<RTBST main copy function; rtbst => rtavl 405>

This code is included in 420 and 457.

450. <RTAVL node copy function 450> =
static int 
copy_node (struct rtavl_table *tree,
           struct rtavl_node *dst, int dir, const struct rtavl_node *src, rtavl_copy_func *copy)
{ struct rtavl_node *new = tree->rtavl_alloc->libavl_malloc (tree->rtavl_alloc, sizeof *new); if (new == NULL) return 0; new->rtavl_link[0] = NULL; new->rtavl_rtag = RTAVL_THREAD; if (dir == 0) new->rtavl_link[1] = dst; else
    { new->rtavl_link[1] = dst->rtavl_link[1]; dst->rtavl_rtag = RTAVL_CHILD; } dst->rtavl_link[dir] = new; new->rtavl_balance = src->rtavl_balance; if (copy == NULL) new->rtavl_data = src->rtavl_data; else
    { new->rtavl_data = copy (src->rtavl_data, tree->rtavl_param); if (new->rtavl_data == NULL) return 0; } return 1; }

This code is included in 449.