VirtualBox

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

Last change on this file since 76553 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.7 KB
Line 
1/* $Id: avl_RemoveBestFit.cpp.h 76553 2019-01-01 01:45:53Z 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) 2006-2019 Oracle Corporation
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 (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.
18 *
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.
24 *
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.
27 */
28
29#ifndef _kAVLRemoveBestFit_h_
30#define _kAVLRemoveBestFit_h_
31
32
33/**
34 * Finds the best fitting node in the tree for the given Key value.
35 * And removes it.
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!
45 */
46KAVL_DECL(PKAVLNODECORE) KAVL_FN(RemoveBestFit)(PPKAVLNODECORE ppTree, KAVLKEY Key, bool fAbove)
47{
48 /*
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.
52 */
53 PKAVLNODECORE pNode = KAVL_FN(GetBestFit)(ppTree, Key, fAbove);
54 if (pNode != NULL)
55 {
56#ifdef KAVL_EQUAL_ALLOWED
57 if (pNode->pList != KAVL_NULL)
58 {
59 PKAVLNODECORE pRet = KAVL_GET_POINTER(&pNode->pList);
60 KAVL_SET_POINTER_NULL(&pNode->pList, &pRet->pList);
61 return pRet;
62 }
63#endif
64 pNode = KAVL_FN(Remove)(ppTree, pNode->Key);
65 }
66 return pNode;
67}
68
69
70#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