static AvlNode* avl_dopy ( AvlNode* nd, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord), void*(alloc_nofail)(const HChar*,SizeT), const HChar* cc ) { AvlNode* nyu; if (! nd) return NULL; nyu = alloc_nofail(cc, sizeof(AvlNode)); tl_assert(nyu); nyu->child[0] = nd->child[0]; nyu->child[1] = nd->child[1]; nyu->balance = nd->balance; /* Copy key */ if (dopyK) { nyu->key = dopyK( nd->key ); if (nd->key != 0 && nyu->key == 0) return NULL; /* oom in key dcopy */ } else { /* copying assumedly unboxed keys */ nyu->key = nd->key; } /* Copy val */ if (dopyV) { nyu->val = dopyV( nd->val ); if (nd->val != 0 && nyu->val == 0) return NULL; /* oom in val dcopy */ } else { /* copying assumedly unboxed vals */ nyu->val = nd->val; } /* Copy subtrees */ if (nyu->child[0]) { nyu->child[0] = avl_dopy( nyu->child[0], dopyK, dopyV, alloc_nofail, cc ); if (! nyu->child[0]) return NULL; } if (nyu->child[1]) { nyu->child[1] = avl_dopy( nyu->child[1], dopyK, dopyV, alloc_nofail, cc ); if (! nyu->child[1]) return NULL; } return nyu; }
static AvlNode* avl_dopy ( AvlNode* nd, Word(*dopyK)(Word), Word(*dopyV)(Word), void*(alloc_nofail)(SizeT) ) { AvlNode* nyu; if (! nd) return NULL; nyu = alloc_nofail(sizeof(AvlNode)); assert(nyu); nyu->left = nd->left; nyu->right = nd->right; nyu->balance = nd->balance; /* Copy key */ if (dopyK) { nyu->key = dopyK( nd->key ); if (nd->key != 0 && nyu->key == 0) return NULL; /* oom in key dcopy */ } else { /* copying assumedly unboxed keys */ nyu->key = nd->key; } /* Copy val */ if (dopyV) { nyu->val = dopyV( nd->val ); if (nd->val != 0 && nyu->val == 0) return NULL; /* oom in val dcopy */ } else { /* copying assumedly unboxed vals */ nyu->val = nd->val; } /* Copy subtrees */ if (nyu->left) { nyu->left = avl_dopy( nyu->left, dopyK, dopyV, alloc_nofail ); if (! nyu->left) return NULL; } if (nyu->right) { nyu->right = avl_dopy( nyu->right, dopyK, dopyV, alloc_nofail ); if (! nyu->right) return NULL; } return nyu; }