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


GNU libavl 2.0.1

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

9.6 Copying

We can use the tree copy function for TBSTs almost verbatim here. The one necessary change is that copy_node() must copy node balance factors. Here's the new version:

 
static int 
copy_node (struct tavl_table *tree,
struct tavl_node *dst, int dir, const struct tavl_node *src, tavl_copy_func *copy)
{ struct tavl_node *new =
tree-&#62;tavl_alloc-&#62;libavl_malloc (tree-&#62;tavl_alloc, sizeof *new); if (new == NULL) return 0; new-&#62;tavl_link[dir] = dst-&#62;tavl_link[dir]; new-&#62;tavl_tag[dir] = TAVL_THREAD; new-&#62;tavl_link[!dir] = dst; new-&#62;tavl_tag[!dir] = TAVL_THREAD; dst-&#62;tavl_link[dir] = new; dst-&#62;tavl_tag[dir] = TAVL_CHILD; new-&#62;tavl_balance = src-&#62;tavl_balance; if (copy == NULL) new-&#62;tavl_data = src-&#62;tavl_data; else
{ new-&#62;tavl_data = copy (src-&#62;tavl_data, tree-&#62;tavl_param); if (new-&#62;tavl_data == NULL) return 0; } return 1; }
This code is included in @refalso{329

 
&#60;@xref{\NODE\, , TAVL node copy function.&#62;,328}
&#60;@xref{\NODE\, , TBST copy error helper function; tbst =>.&#62; tavl,280}
&#60;@xref{\NODE\, , TBST main copy function; tbst =>.&#62; tavl,279}
This code is included in @refalso{300


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