- Timestamp:
- Mar 19, 2000, 5:00:11 PM (25 years ago)
- Location:
- trunk/src/win32k
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/include/avl.h
r2501 r3168 1 /* $Id: avl.h,v 1. 2 2000-01-22 18:20:59bird Exp $1 /* $Id: avl.h,v 1.3 2000-03-19 16:00:10 bird Exp $ 2 2 * 3 3 * AVL-Tree (lookalike) declaration. 4 4 * 5 * Copyright (c) 1999 knut st. osmundsen 5 * This AVL implementation is configurable from this headerfile. By 6 * for example alterning the AVLKEY typedefinition an the AVL_<L|G|E|N>[E] 7 * macros you are able to create different trees. Currently you may only have 8 * one type of trees within one program (module). 9 * 10 * TREETYPE: unsigned long key. 11 * 12 * 13 * Copyright (c) 1999-2000 knut st. osmundsen 6 14 * 7 15 * Project Odin Software License can be found in LICENSE.TXT … … 18 26 * AVL configuration. PRIVATE! 19 27 */ 20 #define AVL_MAX_HEIGHT 19 /* Up to 2^16 nodes. */ 28 #define AVL_MAX_HEIGHT 19 /* Up to 2^16 nodes. */ 29 #undef AVL_MAY_TRY_INSERT_EQUAL /* No duplicate key! */ 30 31 32 /* 33 * AVL Compare macros 34 */ 35 #define AVL_L(key1, key2) ((key1) < (key2)) 36 #define AVL_LE(key1, key2) ((key1) <= (key2)) 37 #define AVL_G(key1, key2) ((key1) > (key2)) 38 #define AVL_GE(key1, key2) ((key1) >= (key2)) 39 #define AVL_E(key1, key2) ((key1) == (key2)) 40 #define AVL_NE(key1, key2) ((key1) != (key2)) 41 21 42 22 43 /** … … 24 45 */ 25 46 typedef unsigned long AVLKEY; 47 26 48 27 49 /** … … 35 57 unsigned char uchHeight; /* Height of this tree: max(heigth(left), heigth(right)) + 1 */ 36 58 } AVLNODECORE, *PAVLNODECORE, **PPAVLNODECORE; 59 37 60 38 61 /** … … 55 78 56 79 57 voidAVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode);80 BOOL AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode); 58 81 PAVLNODECORE AVLRemove(PPAVLNODECORE ppTree, AVLKEY Key); 59 82 PAVLNODECORE AVLGet(PPAVLNODECORE ppTree, AVLKEY Key); -
trunk/src/win32k/misc/avl.c
r2507 r3168 1 /* $Id: avl.c,v 1. 3 2000-01-24 01:45:19bird Exp $1 /* $Id: avl.c,v 1.4 2000-03-19 16:00:11 bird Exp $ 2 2 * 3 3 * AVL-Tree (lookalike) implementation. … … 25 25 #include <os2.h> 26 26 #include "avl.h" 27 #include "dev32.h" 27 #if defined(RING0) || defined(RING3) 28 #include "dev32.h" 29 #else 30 #define SSToDS(a) (a) 31 #endif 32 #include "string.h" 28 33 29 34 #include <builtin.h> … … 58 63 /** 59 64 * Inserts a node into the AVL-tree. 65 * @returns TRUE if inserted. 66 * FALSE if node exists in tree. 60 67 * @param ppTree Pointer to the AVL-tree root node pointer. 61 68 * @param pNode Pointer to the node which is to be added. … … 74 81 * @author knut st. osmundsen 75 82 */ 76 voidAVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode)83 BOOL AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode) 77 84 { 78 85 AVLSTACK AVLStack; … … 87 94 assert(AVLStack.cEntries < AVL_MAX_HEIGHT); 88 95 AVLStack.aEntries[AVLStack.cEntries++] = ppCurNode; 89 if ( pCurNode->Key > Key)96 if (AVL_G(pCurNode->Key, Key)) 90 97 ppCurNode = &pCurNode->pLeft; 91 98 else … … 93 100 } 94 101 102 #ifdef AVL_MAY_TRY_INSERT_EQUAL 103 /* check if equal */ 104 if (AVLStack.cEntries > 0 && AVL_E((*AVLStack.aEntries[AVLStack.cEntries-1])->Key, pNode->Key)) 105 return FALSE; 106 #endif 107 95 108 pNode->pLeft = pNode->pRight = NULL; 96 109 pNode->uchHeight = 1; … … 98 111 99 112 AVLRebalance(SSToDS(&AVLStack)); 113 return TRUE; 100 114 } 101 115 … … 154 168 assert(AVLStack.cEntries < AVL_MAX_HEIGHT); 155 169 AVLStack.aEntries[AVLStack.cEntries++] = ppDeleteNode; 156 if ( pDeleteNode->Key == Key)170 if (AVL_E(pDeleteNode->Key, Key)) 157 171 break; 158 172 159 if ( pDeleteNode->Key > Key)173 if (AVL_G(pDeleteNode->Key, Key)) 160 174 ppDeleteNode = &pDeleteNode->pLeft; 161 175 else … … 215 229 register PAVLNODECORE pNode = *ppTree; 216 230 217 while (pNode != NULL && pNode->Key != Key)218 { 219 if ( pNode->Key > Key)231 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 232 { 233 if (AVL_G(pNode->Key, Key)) 220 234 pNode = pNode->pLeft; 221 235 else … … 244 258 register PAVLNODECORE pParent = NULL; 245 259 246 while (pNode != NULL && pNode->Key != Key)260 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 247 261 { 248 262 pParent = pNode; 249 if ( pNode->Key > Key)263 if (AVL_G(pNode->Key, Key)) 250 264 pNode = pNode->pLeft; 251 265 else … … 285 299 AVLStack.cEntries = 0; 286 300 287 while ((pNode = *ppNode) != NULL && pNode->Key != Key)301 while ((pNode = *ppNode) != NULL && AVL_NE(pNode->Key, Key)) 288 302 { 289 303 assert(AVLStack.cEntries < AVL_MAX_HEIGHT); 290 304 AVLStack.aEntries[AVLStack.cEntries++] = ppNode; 291 if ( pNode->Key > Key)305 if (AVL_G(pNode->Key, Key)) 292 306 ppNode = &pNode->pLeft; 293 307 else … … 317 331 { 318 332 pCurNode = *AVLStack.aEntries[AVLStack.cEntries]; 319 if ( pCurNode->Key < Key && (*ppLeft == NULL || pCurNode->Key > (*ppLeft)->Key))333 if (AVL_L(pCurNode->Key, Key) && (*ppLeft == NULL || AVL_G(pCurNode->Key, (*ppLeft)->Key))) 320 334 *ppLeft = pCurNode; 321 else if ( pCurNode->Key > Key && (*ppRight == NULL || pCurNode->Key < (*ppRight)->Key))335 else if (AVL_G(pCurNode->Key, Key) && (*ppRight == NULL || AVL_L(pCurNode->Key, (*ppRight)->Key))) 322 336 *ppRight = pCurNode; 323 337 } … … 556 570 if (fAbove) 557 571 { /* pNode->Key >= Key */ 558 while (pNode != NULL && pNode->Key != Key)559 { 560 if ( pNode->Key > Key)572 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 573 { 574 if (AVL_G(pNode->Key, Key)) 561 575 { 562 576 pNodeLast = pNode; … … 569 583 else 570 584 { /* pNode->Key <= Key */ 571 while (pNode != NULL && pNode->Key != Key)572 { 573 if ( pNode->Key < Key)585 while (pNode != NULL && AVL_NE(pNode->Key, Key)) 586 { 587 if (AVL_L(pNode->Key, Key)) 574 588 { 575 589 pNodeLast = pNode;
Note:
See TracChangeset
for help on using the changeset viewer.