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/kAVLEnum.h

    r3553 r3555  
    11/* $Id$ */
    22/** @file
    3  *
    4  * kAVLEnum - Enumeration routine for AVL trees.
    5  *
    6  * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net)
    7  *
    8  * GPL
     3 * kAVLTmpl - Templated AVL Trees, Node Enumeration.
    94 */
    105
    11 #ifndef _kAVLEnum_h_
    12 #define _kAVLEnum_h_
    13 
    14 
    15 /**
    16  * Starts an enumeration of all nodes in the given AVL tree.
    17  * @returns   Pointer to the first node in the tree.
    18  * @param     ppTree     Pointer to the AVL-tree root node pointer.
    19  * @param     pEnumData  Pointer to enumeration control data.
    20  * @param     fFromLeft  TRUE:  Left to right.
    21  *                       FALSE: Right to left.
    22  * @status    completely implemented.
    23  * @author    knut st. osmundsen
     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 *
    2425 */
    25 PKAVLNODECORE KLIBCALL KAVL_FN(BeginEnumTree)(PPKAVLNODECORE ppTree, PKAVLENUMDATA pEnumData, int fFromLeft)
    26 {
    27     KLOGENTRY3("PKAVLNODECORE","PPKAVLNODECORE ppTree, PKAVLENUMDATA pEnumData, int fFromLeft", ppTree, pEnumData, fFromLeft);
    28     PKAVLNODECORE    pNode;
    29     if (*ppTree != NULL)
    30     {
    31         pEnumData->fFromLeft = (char)fFromLeft;
    32         pEnumData->cEntries = 1;
    33         pEnumData->aEntries[0] = *ppTree;
    34         pEnumData->achFlags[0] = 0;
    35     }
    36     else
    37         pEnumData->cEntries = 0;
    38 
    39     pNode = KAVL_FN(GetNextNode)(pEnumData);
    40     KLOGEXIT(pNode);
    41     return pNode;
    42 }
    43 
    4426
    4527/**
     
    5032 * @author    knut st. osmundsen
    5133 */
    52 PKAVLNODECORE KLIBCALL KAVL_FN(GetNextNode)(PKAVLENUMDATA pEnumData)
     34KAVL_DECL(KAVLNODECORE *) KAVL_FN(GetNextNode)(KAVL_TYPE(,ENUMDATA) *pEnumData)
    5335{
    54     KLOGENTRY1("PKAVLNODECORE","PKAVLENUMDATA pEnumData", pEnumData);
    55     PKAVLNODECORE    pNode;
    56 
    5736    if (pEnumData->fFromLeft)
    5837    {   /* from left */
    5938        while (pEnumData->cEntries > 0)
    6039        {
    61             pNode = pEnumData->aEntries[pEnumData->cEntries - 1];
     40            KAVLNODECORE *pNode = pEnumData->aEntries[pEnumData->cEntries - 1];
    6241
    6342            /* left */
     
    6544            {
    6645                pEnumData->achFlags[pEnumData->cEntries - 1]++;
    67                 if (pNode->pLeft != NULL)
     46                if (pNode->pLeft != KAVL_NULL)
    6847                {
    6948                    pEnumData->achFlags[pEnumData->cEntries] = 0; /* 0 left, 1 center, 2 right */
    70                     pEnumData->aEntries[pEnumData->cEntries++] = pNode->pLeft;
     49                    pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pLeft);
    7150                    continue;
    7251                }
     
    7756            {
    7857                pEnumData->achFlags[pEnumData->cEntries - 1]++;
    79                 KLOGEXIT(pNode);
    8058                return pNode;
    8159            }
     
    8361            /* right */
    8462            pEnumData->cEntries--;
    85             if (pNode->pRight != NULL)
     63            if (pNode->pRight != KAVL_NULL)
    8664            {
    8765                pEnumData->achFlags[pEnumData->cEntries] = 0;
    88                 pEnumData->aEntries[pEnumData->cEntries++] = pNode->pRight;
     66                pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pRight);
    8967            }
    9068        } /* while */
     
    9472        while (pEnumData->cEntries > 0)
    9573        {
    96             pNode = pEnumData->aEntries[pEnumData->cEntries - 1];
    97 
     74            KAVLNODECORE *pNode = pEnumData->aEntries[pEnumData->cEntries - 1];
    9875
    9976            /* right */
     
    10178            {
    10279                pEnumData->achFlags[pEnumData->cEntries - 1]++;
    103                 if (pNode->pRight != NULL)
     80                if (pNode->pRight != KAVL_NULL)
    10481                {
    10582                    pEnumData->achFlags[pEnumData->cEntries] = 0;  /* 0 right, 1 center, 2 left */
    106                     pEnumData->aEntries[pEnumData->cEntries++] = pNode->pRight;
     83                    pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pRight);
    10784                    continue;
    10885                }
     
    11390            {
    11491                pEnumData->achFlags[pEnumData->cEntries - 1]++;
    115                 KLOGEXIT(pNode);
    11692                return pNode;
    11793            }
     
    11995            /* left */
    12096            pEnumData->cEntries--;
    121             if (pNode->pLeft != NULL)
     97            if (pNode->pLeft != KAVL_NULL)
    12298            {
    12399                pEnumData->achFlags[pEnumData->cEntries] = 0;
    124                 pEnumData->aEntries[pEnumData->cEntries++] = pNode->pLeft;
     100                pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pLeft);
    125101            }
    126102        } /* while */
    127103    }
    128104
    129     KLOGEXIT(NULL);
    130105    return NULL;
    131106}
    132107
    133108
    134 #endif
     109/**
     110 * Starts an enumeration of all nodes in the given AVL tree.
     111 *
     112 * @returns Pointer to the first node in the enumeration.
     113 * @param   ppTree      Pointer to the AVL-tree root node pointer.
     114 * @param   pEnumData   Pointer to enumeration control data.
     115 * @param   fFromLeft   K_TRUE:  Left to right.
     116 *                      K_FALSE: Right to left.
     117 */
     118KAVL_DECL(KAVLNODECORE *) KAVL_FN(BeginEnumTree)(KAVLTREEPTR *ppTree, KAVL_TYPE(,ENUMDATA) *pEnumData, KBOOL fFromLeft)
     119{
     120    if (*ppTree != KAVL_NULL)
     121    {
     122        pEnumData->fFromLeft = fFromLeft;
     123        pEnumData->cEntries = 1;
     124        pEnumData->aEntries[0] = KAVL_GET_POINTER(ppTree);
     125        pEnumData->achFlags[0] = 0;
     126    }
     127    else
     128        pEnumData->cEntries = 0;
    135129
     130    return KAVL_FN(GetNextNode)(pEnumData);
     131}
     132
Note: See TracChangeset for help on using the changeset viewer.