예제 #1
0
void           *
TRE_isInSubTree(void *subTree, void *item, TRE_T * tree)
{
    while (item != subTree) {
	if (!item)
	    return (NULL);

	item = TRE_parent(item);

	if (item == tree)
	    return (NULL);
    }
    return (item);
}
예제 #2
0
/*
 ** FUNCTION:      TRE_copyNextInSubTree
 **
 ** DESCRIPTION:   Copy one item of a sub-tree
 **
 ** RETURNS:       void *
 */
void           *
TRE_copyNextInSubTree(TRE_COPY_T * copy, void *looseItem)
{
    int             steps;

    if (!copy->sourcePrev) {
	TRE_addChild(looseItem, copy->destRoot);
	copy->subRoot = looseItem;	/* Log this item for later */
    } else if (TRE_areSiblings(copy->sourceCurrent, copy->sourcePrev)) {
	TRE_addSibling(looseItem, copy->destCurrent);
    } else {
	/*
	 * must link to correct parent in new subtree: do this by
	 * exploiting isomorphism in those parts of the source and
	 * destination subtrees already copied so far. 
	 */
	steps = _TRE_subTreeSteps(copy->sourceRoot,
				  TRE_parent(copy->sourceCurrent),
				  copy->sourceTree);

	{
	    void           *a;
	    int             i;

	    a = copy->subRoot;
	    for (i = 0; i < steps; i++)
		a = TRE_subTreeNext(copy->subRoot, a, copy->sourceTree);
	    TRE_addChild(looseItem, a);
	}
    }

    /*
     * Increment the source and destination item pointers 
     */
    copy->sourcePrev = copy->sourceCurrent;
    copy->sourceCurrent = TRE_subTreeNext(copy->sourceRoot,
					  copy->sourceCurrent,
					  copy->sourceTree);
    copy->destCurrent = looseItem;

    /*
     * return the next source item to copy or NULL if it is time to stop. 
     */
    return (copy->sourceCurrent);
}