VirtualBox

Changeset 33268 in vbox


Ignore:
Timestamp:
Oct 20, 2010 3:37:15 PM (14 years ago)
Author:
vboxsync
Message:

IPRT: Added an AVL tree taking void * ranges.

Location:
trunk
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/avl.h

    r32284 r33268  
    124124
    125125
     126/** AVL tree of void pointer ranges.
     127 * @{
     128 */
     129
     130/**
     131 * AVL key type
     132 */
     133typedef void *AVLRPVKEY;
     134
     135/**
     136 * AVL Core node.
     137 */
     138typedef struct AVLRPVNodeCore
     139{
     140    AVLRPVKEY               Key;        /**< First key value in the range (inclusive). */
     141    AVLRPVKEY               KeyLast;    /**< Last key value in the range (inclusive). */
     142    struct AVLRPVNodeCore  *pLeft;      /**< Pointer to left leaf node. */
     143    struct AVLRPVNodeCore  *pRight;     /**< Pointer to right leaf node. */
     144    unsigned char           uchHeight;  /**< Height of this tree: max(height(left), height(right)) + 1 */
     145} AVLRPVNODECORE, *PAVLRPVNODECORE, **PPAVLRPVNODECORE;
     146
     147/** A tree with void pointer keys. */
     148typedef PAVLRPVNODECORE    AVLRPVTREE;
     149/** Pointer to a tree with void pointer keys. */
     150typedef PPAVLRPVNODECORE   PAVLRPVTREE;
     151
     152/** Callback function for AVLPVDoWithAll(). */
     153typedef DECLCALLBACK(int) AVLRPVCALLBACK(PAVLRPVNODECORE, void *);
     154/** Pointer to callback function for AVLPVDoWithAll(). */
     155typedef AVLRPVCALLBACK *PAVLRPVCALLBACK;
     156
     157/*
     158 * Functions.
     159 */
     160RTDECL(bool)            RTAvlrPVInsert(PAVLRPVTREE ppTree, PAVLRPVNODECORE pNode);
     161RTDECL(PAVLRPVNODECORE) RTAvlrPVRemove(PAVLRPVTREE ppTree, AVLRPVKEY Key);
     162RTDECL(PAVLRPVNODECORE) RTAvlrPVGet(PAVLRPVTREE ppTree, AVLRPVKEY Key);
     163RTDECL(PAVLRPVNODECORE) RTAvlrPVRangeGet(PAVLRPVTREE ppTree, AVLRPVKEY Key);
     164RTDECL(PAVLRPVNODECORE) RTAvlrPVRangeRemove(PAVLRPVTREE ppTree, AVLRPVKEY Key);
     165RTDECL(PAVLRPVNODECORE) RTAvlrPVGetBestFit(PAVLRPVTREE ppTree, AVLRPVKEY Key, bool fAbove);
     166RTDECL(PAVLRPVNODECORE) RTAvlrPVRemoveBestFit(PAVLRPVTREE ppTree, AVLRPVKEY Key, bool fAbove);
     167RTDECL(int)             RTAvlrPVDoWithAll(PAVLRPVTREE ppTree, int fFromLeft, PAVLRPVCALLBACK pfnCallBack, void *pvParam);
     168RTDECL(int)             RTAvlrPVDestroy(PAVLRPVTREE ppTree, PAVLRPVCALLBACK pfnCallBack, void *pvParam);
     169
     170/** @} */
     171
     172
     173
    126174/** AVL tree of uint32_t
    127175 * @{
  • trunk/src/VBox/Runtime/common/table/avlrpv.cpp

    r33145 r33268  
    11/* $Id$ */
    22/** @file
    3  * IPRT - AVL tree, void *, unique keys.
     3 * IPRT - AVL tree, void *, range, unique keys.
    44 */
    55
     
    3535 * AVL configuration.
    3636 */
    37 #define KAVL_FN(a)                  RTAvlPV##a
     37#define KAVL_FN(a)                  RTAvlrPV##a
    3838#define KAVL_MAX_STACK              27  /* Up to 2^24 nodes. */
    3939#define KAVL_CHECK_FOR_EQUAL_INSERT 1   /* No duplicate keys! */
    40 #define KAVLNODECORE                AVLPVNODECORE
    41 #define PKAVLNODECORE               PAVLPVNODECORE
    42 #define PPKAVLNODECORE              PPAVLPVNODECORE
    43 #define KAVLKEY                     AVLPVKEY
    44 #define PKAVLKEY                    PAVLPVKEY
    45 #define KAVLENUMDATA                AVLPVENUMDATA
    46 #define PKAVLENUMDATA               PAVLPVENUMDATA
    47 #define PKAVLCALLBACK               PAVLPVCALLBACK
     40#define KAVLNODECORE                AVLRPVNODECORE
     41#define PKAVLNODECORE               PAVLRPVNODECORE
     42#define PPKAVLNODECORE              PPAVLRPVNODECORE
     43#define KAVLKEY                     AVLRPVKEY
     44#define PKAVLKEY                    PAVLRPVKEY
     45#define KAVLENUMDATA                AVLRPVENUMDATA
     46#define PKAVLENUMDATA               PAVLRPVENUMDATA
     47#define PKAVLCALLBACK               PAVLRPVCALLBACK
     48#define KAVL_RANGE                  1
    4849
    4950
     
    5152 * AVL Compare macros
    5253 */
    53 #define KAVL_G(key1, key2)          ( (const char*)(key1) >  (const char*)(key2) )
    54 #define KAVL_E(key1, key2)          ( (const char*)(key1) == (const char*)(key2) )
    55 #define KAVL_NE(key1, key2)         ( (const char*)(key1) != (const char*)(key2) )
     54#define KAVL_G(key1, key2)          ( (uintptr_t)(key1) >  (uintptr_t)(key2) )
     55#define KAVL_E(key1, key2)          ( (uintptr_t)(key1) == (uintptr_t)(key2) )
     56#define KAVL_NE(key1, key2)         ( (uintptr_t)(key1) != (uintptr_t)(key2) )
     57#define KAVL_R_IS_IDENTICAL(key1B, key2B, key1E, key2E)     ( (uintptr_t)(key1B) == (uintptr_t)(key2B) && (uintptr_t)(key1E) == (uintptr_t)(key2E) )
     58#define KAVL_R_IS_INTERSECTING(key1B, key2B, key1E, key2E)  ( (uintptr_t)(key1B) <= (uintptr_t)(key2E) && (uintptr_t)(key1E) >= (uintptr_t)(key2B) )
     59#define KAVL_R_IS_IN_RANGE(key1B, key1E, key2)              KAVL_R_IS_INTERSECTING(key1B, key2, key1E, key2)
    5660
    5761
     
    7276#include "avl_Get.cpp.h"
    7377#include "avl_GetBestFit.cpp.h"
     78#include "avl_Range.cpp.h"
    7479#include "avl_RemoveBestFit.cpp.h"
    7580#include "avl_DoWithAll.cpp.h"
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette