GNU libavl 2.0.1
Author: Ben Pfaff

11.6 Copying |

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.

    447. <RTAVL copy function 447> =
    <RTAVL node copy function 448>
    <RTBST copy error helper function; rtbst => rtavl 405>
    <RTBST main copy function; rtbst => rtavl 403>

This code is included in 418 and 455.

    448. <RTAVL node copy function 448> =
    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 447.

11.5.4 Step 4: Rebalance | 11 Right-Threaded AVL Trees | 11.7 Testing