Ignore:
Timestamp:
Mar 19, 2000, 5:00:11 PM (25 years ago)
Author:
bird
Message:

Synced with \tools\fastdep\avl.*

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:19 bird Exp $
     1/* $Id: avl.c,v 1.4 2000-03-19 16:00:11 bird Exp $
    22 *
    33 * AVL-Tree (lookalike) implementation.
     
    2525#include <os2.h>
    2626#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"
    2833
    2934#include <builtin.h>
     
    5863/**
    5964 * Inserts a node into the AVL-tree.
     65 * @returns   TRUE if inserted.
     66 *            FALSE if node exists in tree.
    6067 * @param     ppTree  Pointer to the AVL-tree root node pointer.
    6168 * @param     pNode   Pointer to the node which is to be added.
     
    7481 * @author    knut st. osmundsen
    7582 */
    76 void AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode)
     83BOOL AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode)
    7784{
    7885    AVLSTACK                AVLStack;
     
    8794        assert(AVLStack.cEntries < AVL_MAX_HEIGHT);
    8895        AVLStack.aEntries[AVLStack.cEntries++] = ppCurNode;
    89         if (pCurNode->Key > Key)
     96        if (AVL_G(pCurNode->Key, Key))
    9097            ppCurNode = &pCurNode->pLeft;
    9198        else
     
    93100    }
    94101
     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
    95108    pNode->pLeft = pNode->pRight = NULL;
    96109    pNode->uchHeight = 1;
     
    98111
    99112    AVLRebalance(SSToDS(&AVLStack));
     113    return TRUE;
    100114}
    101115
     
    154168        assert(AVLStack.cEntries < AVL_MAX_HEIGHT);
    155169        AVLStack.aEntries[AVLStack.cEntries++] = ppDeleteNode;
    156         if (pDeleteNode->Key == Key)
     170        if (AVL_E(pDeleteNode->Key, Key))
    157171            break;
    158172
    159         if (pDeleteNode->Key > Key)
     173        if (AVL_G(pDeleteNode->Key, Key))
    160174            ppDeleteNode = &pDeleteNode->pLeft;
    161175        else
     
    215229    register PAVLNODECORE  pNode = *ppTree;
    216230
    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))
    220234            pNode = pNode->pLeft;
    221235        else
     
    244258    register PAVLNODECORE  pParent = NULL;
    245259
    246     while (pNode != NULL && pNode->Key != Key)
     260    while (pNode != NULL && AVL_NE(pNode->Key, Key))
    247261    {
    248262        pParent = pNode;
    249         if (pNode->Key > Key)
     263        if (AVL_G(pNode->Key, Key))
    250264            pNode = pNode->pLeft;
    251265        else
     
    285299    AVLStack.cEntries = 0;
    286300
    287     while ((pNode = *ppNode) != NULL && pNode->Key != Key)
     301    while ((pNode = *ppNode) != NULL && AVL_NE(pNode->Key, Key))
    288302    {
    289303        assert(AVLStack.cEntries < AVL_MAX_HEIGHT);
    290304        AVLStack.aEntries[AVLStack.cEntries++] = ppNode;
    291         if (pNode->Key > Key)
     305        if (AVL_G(pNode->Key, Key))
    292306            ppNode = &pNode->pLeft;
    293307        else
     
    317331        {
    318332            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)))
    320334                *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)))
    322336                *ppRight = pCurNode;
    323337        }
     
    556570    if (fAbove)
    557571    {   /* 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))
    561575            {
    562576                pNodeLast = pNode;
     
    569583    else
    570584    {   /* 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))
    574588            {
    575589                pNodeLast = pNode;
Note: See TracChangeset for help on using the changeset viewer.