VirtualBox

source: vbox/trunk/src/VBox/Runtime/table/avl_RemoveBestFit.cpp.h@ 980

Last change on this file since 980 was 402, checked in by vboxsync, 18 years ago

Added missing RTDECL so it'll compile cleanly in Ring-0 on NT where default calling convention is stdcall and not cdecl like RTCALL.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1/* $Id: avl_RemoveBestFit.cpp.h 402 2007-01-28 08:44:20Z vboxsync $ */
2/** @file
3 * kAVLRemoveBestFit - Remove Best Fit routine for AVL trees.
4 * Intended specially on heaps. The tree should allow duplicate keys.
5 *
6 */
7
8/*
9 * Copyright (C) 1999-2002 knut st. osmundsen (bird-src-spam@anduin.net)
10 *
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 as published by the Free Software Foundation,
15 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
16 * distribution. VirtualBox OSE is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * If you received this file as part of a commercial VirtualBox
20 * distribution, then only the terms of your commercial VirtualBox
21 * license agreement apply instead of the previous paragraph.
22 */
23
24#ifndef _kAVLRemoveBestFit_h_
25#define _kAVLRemoveBestFit_h_
26
27
28/**
29 * Finds the best fitting node in the tree for the given Key value.
30 * And removes it.
31 * @returns Pointer to the best fitting node found.
32 * @param ppTree Pointer to Pointer to the tree root node.
33 * @param Key The Key of which is to be found a best fitting match for..
34 * @param fAbove TRUE: Returned node is have the closest key to Key from above.
35 * FALSE: Returned node is have the closest key to Key from below.
36 * @sketch The best fitting node is always located in the searchpath above you.
37 * >= (above): The node where you last turned left.
38 * <= (below): the node where you last turned right.
39 * @remark This implementation should be speeded up slightly!
40 */
41RTDECL(PKAVLNODECORE) KAVL_FN(RemoveBestFit)(PPKAVLNODECORE ppTree, KAVLKEY Key, bool fAbove)
42{
43 /*
44 * If we find anything we'll have to remove the node and return it.
45 * But, if duplicate keys are allowed we'll have to check for multiple
46 * nodes first and return one of them before doing an expensive remove+insert.
47 */
48 PKAVLNODECORE pNode = KAVL_FN(GetBestFit)(ppTree, Key, fAbove);
49 if (pNode != NULL)
50 {
51 #ifdef KAVL_EQUAL_ALLOWED
52 if (pNode->pList != KAVL_NULL)
53 {
54 PKAVLANODECORE pRet = KAVL_GET_POINTER(&pNode->pList);
55 KAVL_SET_POINTER_NULL(&pNode->pList, &pRet->pList);
56 return pRet;
57 }
58 #endif
59 pNode = KAVL_FN(Remove)(ppTree, pNode->Key);
60 }
61 return pNode;
62}
63
64
65#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette