1 | /* $Id: avl_Get.cpp.h 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * kAVLGet - get routine for AVL trees.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 1999-2012 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 |
|
---|
27 | #ifndef _kAVLGet_h_
|
---|
28 | #define _kAVLGet_h_
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Gets a node from the tree (does not remove it!)
|
---|
33 | * @returns Pointer to the node holding the given key.
|
---|
34 | * @param ppTree Pointer to the AVL-tree root node pointer.
|
---|
35 | * @param Key Key value of the node which is to be found.
|
---|
36 | * @author knut st. osmundsen
|
---|
37 | */
|
---|
38 | KAVL_DECL(PKAVLNODECORE) KAVL_FN(Get)(PPKAVLNODECORE ppTree, KAVLKEY Key)
|
---|
39 | {
|
---|
40 | register PKAVLNODECORE pNode = KAVL_GET_POINTER_NULL(ppTree);
|
---|
41 |
|
---|
42 | if (pNode)
|
---|
43 | {
|
---|
44 | while (KAVL_NE(pNode->Key, Key))
|
---|
45 | {
|
---|
46 | if (KAVL_G(pNode->Key, Key))
|
---|
47 | {
|
---|
48 | if (pNode->pLeft != KAVL_NULL)
|
---|
49 | pNode = KAVL_GET_POINTER(&pNode->pLeft);
|
---|
50 | else
|
---|
51 | return NULL;
|
---|
52 | }
|
---|
53 | else
|
---|
54 | {
|
---|
55 | if (pNode->pRight != KAVL_NULL)
|
---|
56 | pNode = KAVL_GET_POINTER(&pNode->pRight);
|
---|
57 | else
|
---|
58 | return NULL;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | return pNode;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | #endif
|
---|