avl_RemoveNode.cpp.h revision c46e2b58f1dbcc439834b260c799b3d3027150e1
/* $Id$ */
/** @file
* kAVLRemove2 - Remove specific node (by pointer) from an AVL tree.
*/
/*
* Copyright (C) 2001-2002 knut st. osmundsen (bird-src-spam@anduin.net)
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/**
* Removes the specified node from the tree.
*
* @returns Pointer to the removed node (NULL if not in the tree)
* @param ppTree Pointer to the AVL-tree root structure.
* @param pNode Pointer to the node to be removed.
*
* @remark This implementation isn't the most efficient, but it's relatively
* short and easier to manage.
*/
{
#ifdef KAVL_EQUAL_ALLOWED
/*
* Find the right node by key together with the parent node.
*/
if (!pCurNode)
return NULL;
{
{
else
return NULL;
}
else
{
else
return NULL;
}
}
{
/*
* It's not the one we want, but it could be in the duplicate list.
*/
{
{
else
return pNode;
}
}
return NULL;
}
/*
* Ok, it's the one we want alright.
*
* Simply remove it if it's the only one with they Key, if there are
* duplicates we'll have to unlink it and insert the first duplicate
* in our place.
*/
else
{
else
else
if (pParent)
{
else
}
else
}
return pNode;
#else
/*
* Delete it, if we got the wrong one, reinsert it.
*
* This ASSUMS that the caller is NOT going to hand us a lot
* of wrong nodes but just uses this API for his convenience.
*/
if (pRemovedNode == pNode)
return pRemovedNode;
return NULL;
#endif
}