VirtualBox

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

Last change on this file since 4953 was 4687, checked in by vboxsync, 17 years ago

Added RTAvllU32*. Applied enumeration fixes for non-unique tree. Applied Destroy fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1/* $Id: avl_RemoveBestFit.cpp.h 4687 2007-09-11 09:13:32Z 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
20#ifndef _kAVLRemoveBestFit_h_
21#define _kAVLRemoveBestFit_h_
22
23
24/**
25 * Finds the best fitting node in the tree for the given Key value.
26 * And removes it.
27 * @returns Pointer to the best fitting node found.
28 * @param ppTree Pointer to Pointer to the tree root node.
29 * @param Key The Key of which is to be found a best fitting match for..
30 * @param fAbove TRUE: Returned node is have the closest key to Key from above.
31 * FALSE: Returned node is have the closest key to Key from below.
32 * @sketch The best fitting node is always located in the searchpath above you.
33 * >= (above): The node where you last turned left.
34 * <= (below): the node where you last turned right.
35 * @remark This implementation should be speeded up slightly!
36 */
37RTDECL(PKAVLNODECORE) KAVL_FN(RemoveBestFit)(PPKAVLNODECORE ppTree, KAVLKEY Key, bool fAbove)
38{
39 /*
40 * If we find anything we'll have to remove the node and return it.
41 * But, if duplicate keys are allowed we'll have to check for multiple
42 * nodes first and return one of them before doing an expensive remove+insert.
43 */
44 PKAVLNODECORE pNode = KAVL_FN(GetBestFit)(ppTree, Key, fAbove);
45 if (pNode != NULL)
46 {
47#ifdef KAVL_EQUAL_ALLOWED
48 if (pNode->pList != KAVL_NULL)
49 {
50 PKAVLNODECORE pRet = KAVL_GET_POINTER(&pNode->pList);
51 KAVL_SET_POINTER_NULL(&pNode->pList, &pRet->pList);
52 return pRet;
53 }
54#endif
55 pNode = KAVL_FN(Remove)(ppTree, pNode->Key);
56 }
57 return pNode;
58}
59
60
61#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