www.delorie.com/gnu/docs/avl/libavl_214.html   search  
 
Buy GNU books!


GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.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.

 
&#60;@xref{\NODE\, , RTAVL node copy function.&#62;,448}
&#60;@xref{\NODE\, , RTBST copy error helper function; rtbst =>.&#62; rtavl,405}
&#60;@xref{\NODE\, , RTBST main copy function; rtbst =>.&#62; rtavl,403}
This code is included in @refalso{418

 
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-&#62;rtavl_alloc-&#62;libavl_malloc (tree-&#62;rtavl_alloc, sizeof *new); if (new == NULL) return 0; new-&#62;rtavl_link[0] = NULL; new-&#62;rtavl_rtag = RTAVL_THREAD; if (dir == 0) new-&#62;rtavl_link[1] = dst; else
{ new-&#62;rtavl_link[1] = dst-&#62;rtavl_link[1]; dst-&#62;rtavl_rtag = RTAVL_CHILD; } dst-&#62;rtavl_link[dir] = new; new-&#62;rtavl_balance = src-&#62;rtavl_balance; if (copy == NULL) new-&#62;rtavl_data = src-&#62;rtavl_data; else
{ new-&#62;rtavl_data = copy (src-&#62;rtavl_data, tree-&#62;rtavl_param); if (new-&#62;rtavl_data == NULL) return 0; } return 1; }
This code is included in @refalso{447


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003