Ignore:
Timestamp:
Aug 26, 2007, 12:43:27 PM (18 years ago)
Author:
bird
Message:

Merging in kAvl enhancements, doing some config simplications and made them inlineable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/include/k/kAVLTmpl/kAVLGet.h

    r3553 r3555  
    11/* $Id$ */
    22/** @file
    3  *
    4  * kAVLGet - get routine for AVL trees.
    5  *
    6  * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net)
    7  *
    8  * GPL
     3 * kAVLTmpl - Templated AVL Trees, Get a Node.
    94 */
    105
    11 #ifndef _kAVLGet_h_
    12 #define _kAVLGet_h_
     6/*
     7 * Copyright (c) 1999-2007 knut st. osmundsen <bird-src-spam@anduin.net>
     8 *
     9 * This file is part of kStuff.
     10 *
     11 * kStuff is free software; you can redistribute it and/or
     12 * modify it under the terms of the GNU Lesser General Public
     13 * License as published by the Free Software Foundation; either
     14 * version 2.1 of the License, or (at your option) any later version.
     15 *
     16 * kStuff is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19 * Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public
     22 * License along with kStuff; if not, write to the Free Software
     23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     24 *
     25 */
    1326
    1427
    1528/**
    1629 * Gets a node from the tree (does not remove it!)
     30 *
    1731 * @returns   Pointer to the node holding the given key.
    1832 * @param     ppTree  Pointer to the AVL-tree root node pointer.
    1933 * @param     Key     Key value of the node which is to be found.
    20  * @sketch
    21  * @status    completely implemented.
    22  * @author    knut st. osmundsen
    2334 */
    24 PKAVLNODECORE KLIBCALL KAVL_FN(Get)(PPKAVLNODECORE ppTree, KAVLKEY Key)
     35KAVL_DECL(KAVLNODECORE *) KAVL_FN(Get)(KAVLTREEPTR *ppTree, KAVLKEY Key)
    2536{
    26     KLOGENTRY2("PKAVLNODECORE","PPKAVLNODECORE ppTree, KAVLKEY Key", ppTree, Key);
    27     #ifndef AVL_CMP
    28     register PKAVLNODECORE   pNode = *ppTree;
     37    KAVLNODECORE *pNode;
     38    if (*ppTree == KAVL_NULL)
     39        return NULL;
    2940
    30     while (pNode != NULL && AVL_NE(pNode->Key, Key))
     41    pNode = KAVL_GET_POINTER(ppTree);
     42    while (KAVL_NE(pNode->Key, Key))
    3143    {
    32         if (AVL_G(pNode->Key, Key))
    33             pNode = pNode->pLeft;
     44        if (KAVL_G(pNode->Key, Key))
     45        {
     46            if (pNode->pLeft == KAVL_NULL)
     47                return NULL;
     48            pNode = KAVL_GET_POINTER(&pNode->pLeft);
     49        }
    3450        else
    35             pNode = pNode->pRight;
     51        {
     52            if (pNode->pRight == KAVL_NULL)
     53                return NULL;
     54            pNode = KAVL_GET_POINTER(&pNode->pRight);
     55        }
    3656    }
    37 
    38     #else
    39 
    40     register int            iDiff;
    41     register PKAVLNODECORE   pNode = *ppTree;
    42 
    43     while (pNode != NULL && (iDiff = AVL_CMP(pNode->Key, Key)) != 0)
    44     {
    45         if (iDiff > 0)
    46             pNode = pNode->pLeft;
    47         else
    48             pNode = pNode->pRight;
    49     }
    50 
    51     #endif
    52 
    53     KLOGEXIT(pNode);
    5457    return pNode;
    5558}
    5659
    57 
    58 #endif
Note: See TracChangeset for help on using the changeset viewer.