Changeset 3168 for trunk/src


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

Synced with \tools\fastdep\avl.*

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:59 bird Exp $
     1/* $Id: avl.h,v 1.3 2000-03-19 16:00:10 bird Exp $
    22 *
    33 * AVL-Tree (lookalike) declaration.
    44 *
    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
    614 *
    715 * Project Odin Software License can be found in LICENSE.TXT
     
    1826 * AVL configuration. PRIVATE!
    1927 */
    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
    2142
    2243/**
     
    2445 */
    2546typedef unsigned long AVLKEY;
     47
    2648
    2749/**
     
    3557    unsigned char           uchHeight; /* Height of this tree: max(heigth(left), heigth(right)) + 1 */
    3658} AVLNODECORE, *PAVLNODECORE, **PPAVLNODECORE;
     59
    3760
    3861/**
     
    5578
    5679
    57 void            AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode);
     80BOOL            AVLInsert(PPAVLNODECORE ppTree, PAVLNODECORE pNode);
    5881PAVLNODECORE    AVLRemove(PPAVLNODECORE ppTree, AVLKEY Key);
    5982PAVLNODECORE    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: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.