1 | /* $Id: avl_Range.cpp.h 8155 2008-04-18 15:16:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * kAVLRange - Range routines for AVL trees.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 1999-2006 knut st. osmundsen (bird-src-spam@anduin.net)
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef _kAVLRange_h_
|
---|
32 | #define _kAVLRange_h_
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Finds the range containing the specified key.
|
---|
36 | *
|
---|
37 | * @returns Pointer to the matching range.
|
---|
38 | *
|
---|
39 | * @param ppTree Pointer to Pointer to the tree root node.
|
---|
40 | * @param Key The Key to find matching range for.
|
---|
41 | */
|
---|
42 | RTDECL(PKAVLNODECORE) KAVL_FN(RangeGet)(PPKAVLNODECORE ppTree, register KAVLKEY Key)
|
---|
43 | {
|
---|
44 | register PKAVLNODECORE pNode = KAVL_GET_POINTER_NULL(ppTree);
|
---|
45 | if (pNode)
|
---|
46 | {
|
---|
47 | for (;;)
|
---|
48 | {
|
---|
49 | if (KAVL_R_IS_IN_RANGE(pNode->Key, pNode->KeyLast, Key))
|
---|
50 | return pNode;
|
---|
51 | if (KAVL_G(pNode->Key, Key))
|
---|
52 | {
|
---|
53 | if (pNode->pLeft != KAVL_NULL)
|
---|
54 | pNode = KAVL_GET_POINTER(&pNode->pLeft);
|
---|
55 | else
|
---|
56 | return NULL;
|
---|
57 | }
|
---|
58 | else
|
---|
59 | {
|
---|
60 | if (pNode->pRight != KAVL_NULL)
|
---|
61 | pNode = KAVL_GET_POINTER(&pNode->pRight);
|
---|
62 | else
|
---|
63 | return NULL;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | return NULL;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Removes the range containing the specified key.
|
---|
74 | *
|
---|
75 | * @returns Pointer to the matching range.
|
---|
76 | *
|
---|
77 | * @param ppTree Pointer to Pointer to the tree root node.
|
---|
78 | * @param Key The Key to remove matching range for.
|
---|
79 | */
|
---|
80 | RTDECL(PKAVLNODECORE) KAVL_FN(RangeRemove)(PPKAVLNODECORE ppTree, KAVLKEY Key)
|
---|
81 | {
|
---|
82 | PKAVLNODECORE pNode = KAVL_FN(RangeGet)(ppTree, Key);
|
---|
83 | if (pNode)
|
---|
84 | return KAVL_FN(Remove)(ppTree, pNode->Key);
|
---|
85 | return NULL;
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endif
|
---|