Changeset 3168 for trunk/src/win32k/misc/avl.c
- Timestamp:
- Mar 19, 2000, 5:00:11 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.