]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - ubuntu/vbox/vboxguest/common/table/avl_RemoveBestFit.cpp.h
1 /* $Id: avl_RemoveBestFit.cpp.h $ */
3 * kAVLRemoveBestFit - Remove Best Fit routine for AVL trees.
4 * Intended specially on heaps. The tree should allow duplicate keys.
9 * Copyright (C) 2006-2017 Oracle Corporation
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 * The contents of this file may alternatively be used under the terms
20 * of the Common Development and Distribution License Version 1.0
21 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
22 * VirtualBox OSE distribution, in which case the provisions of the
23 * CDDL are applicable instead of those of the GPL.
25 * You may elect to license modified versions of this file under the
26 * terms and conditions of either the GPL or the CDDL or both.
29 #ifndef _kAVLRemoveBestFit_h_
30 #define _kAVLRemoveBestFit_h_
34 * Finds the best fitting node in the tree for the given Key value.
36 * @returns Pointer to the best fitting node found.
37 * @param ppTree Pointer to Pointer to the tree root node.
38 * @param Key The Key of which is to be found a best fitting match for..
39 * @param fAbove TRUE: Returned node is have the closest key to Key from above.
40 * FALSE: Returned node is have the closest key to Key from below.
41 * @sketch The best fitting node is always located in the searchpath above you.
42 * >= (above): The node where you last turned left.
43 * <= (below): the node where you last turned right.
44 * @remark This implementation should be speeded up slightly!
46 KAVL_DECL(PKAVLNODECORE
) KAVL_FN(RemoveBestFit
)(PPKAVLNODECORE ppTree
, KAVLKEY Key
, bool fAbove
)
49 * If we find anything we'll have to remove the node and return it.
50 * But, if duplicate keys are allowed we'll have to check for multiple
51 * nodes first and return one of them before doing an expensive remove+insert.
53 PKAVLNODECORE pNode
= KAVL_FN(GetBestFit
)(ppTree
, Key
, fAbove
);
56 #ifdef KAVL_EQUAL_ALLOWED
57 if (pNode
->pList
!= KAVL_NULL
)
59 PKAVLNODECORE pRet
= KAVL_GET_POINTER(&pNode
->pList
);
60 KAVL_SET_POINTER_NULL(&pNode
->pList
, &pRet
->pList
);
64 pNode
= KAVL_FN(Remove
)(ppTree
, pNode
->Key
);