VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/table/avl_Range.cpp.h@ 5422

Last change on this file since 5422 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/* $Id: avl_Range.cpp.h 4071 2007-08-07 17:07:59Z 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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef _kAVLRange_h_
19#define _kAVLRange_h_
20
21/**
22 * Finds the range containing the specified key.
23 *
24 * @returns Pointer to the matching range.
25 *
26 * @param ppTree Pointer to Pointer to the tree root node.
27 * @param Key The Key to find matching range for.
28 */
29RTDECL(PKAVLNODECORE) KAVL_FN(RangeGet)(PPKAVLNODECORE ppTree, register KAVLKEY Key)
30{
31 register PKAVLNODECORE pNode = KAVL_GET_POINTER_NULL(ppTree);
32 if (pNode)
33 {
34 for (;;)
35 {
36 if (KAVL_R_IS_IN_RANGE(pNode->Key, pNode->KeyLast, Key))
37 return pNode;
38 if (KAVL_G(pNode->Key, Key))
39 {
40 if (pNode->pLeft != KAVL_NULL)
41 pNode = KAVL_GET_POINTER(&pNode->pLeft);
42 else
43 return NULL;
44 }
45 else
46 {
47 if (pNode->pRight != KAVL_NULL)
48 pNode = KAVL_GET_POINTER(&pNode->pRight);
49 else
50 return NULL;
51 }
52 }
53 }
54
55 return NULL;
56}
57
58
59/**
60 * Removes the range containing the specified key.
61 *
62 * @returns Pointer to the matching range.
63 *
64 * @param ppTree Pointer to Pointer to the tree root node.
65 * @param Key The Key to remove matching range for.
66 */
67RTDECL(PKAVLNODECORE) KAVL_FN(RangeRemove)(PPKAVLNODECORE ppTree, KAVLKEY Key)
68{
69 PKAVLNODECORE pNode = KAVL_FN(RangeGet)(ppTree, Key);
70 if (pNode)
71 return KAVL_FN(Remove)(ppTree, pNode->Key);
72 return NULL;
73}
74
75#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