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

    r3553 r3555  
    11/* $Id$ */
    22/** @file
    3  *
    4  * kAVLDoWithAll - Do with all nodes routine for AVL trees.
    5  *
    6  * Copyright (c) 1999-2002 knut st. osmundsen (bird@anduin.net)
    7  *
    8  * GPL
     3 * kAVLTmpl - Templated AVL Trees, The Callback Iterator.
    94 */
    105
    11 #ifndef _kAVLDoWithAll_h_
    12 #define _kAVLDoWithAll_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 * Iterates tru all nodes in the given tree.
    17  * @returns   0 on success. Return from callback on failiure.
    18  * @param     ppTree   Pointer to the AVL-tree root node pointer.
    19  * @param     fFromLeft    TRUE:  Left to right.
    20  *                         FALSE: Right to left.
     30 *
     31 * @returns   0 on success. Return from callback on failure.
     32 * @param     ppTree       Pointer to the AVL-tree root node pointer.
     33 * @param     fFromLeft    K_TRUE:  Left to right.
     34 *                         K_FALSE: Right to left.
    2135 * @param     pfnCallBack  Pointer to callback function.
    22  * @param     pvParam      Userparameter passed on to the callback function.
    23  * @status    completely implemented.
    24  * @author    knut st. osmundsen
     36 * @param     pvUser       User parameter passed on to the callback function.
    2537 */
    26 unsigned KLIBCALL KAVL_FN(DoWithAll)(PPKAVLNODECORE ppTree, int fFromLeft, PKAVLCALLBACK pfnCallBack, void * pvParam)
     38KAVL_DECL(int) KAVL_FN(DoWithAll)(KAVLTREEPTR *ppTree, KBOOL fFromLeft, KAVL_TYPE(PFN,CALLBACK) pfnCallBack, void *pvUser)
    2739{
    28     KLOGENTRY4("unsigned","PPKAVLNODECORE ppTree, int fFromLeft, PKAVLCALLBACK pfnCallBack, void * pvParam", ppTree, fFromLeft, pfnCallBack, pvParam);
    29     KAVLSTACK2       AVLStack;
    30     PKAVLNODECORE    pNode;
    31     unsigned        rc;
     40    KAVL_INT(STACK2)   AVLStack;
     41    KAVLNODECORE       *pNode;
     42    unsigned            rc;
    3243
    33     if (*ppTree == NULL)
     44    if (*ppTree == KAVL_NULL)
    3445        return 0;
    3546
    3647    AVLStack.cEntries = 1;
    3748    AVLStack.achFlags[0] = 0;
    38     AVLStack.aEntries[0] = *ppTree;
     49    AVLStack.aEntries[0] = KAVL_GET_POINTER(ppTree);
    3950
    4051    if (fFromLeft)
     
    4758            if (!AVLStack.achFlags[AVLStack.cEntries - 1]++)
    4859            {
    49                 if (pNode->pLeft != NULL)
     60                if (pNode->pLeft != KAVL_NULL)
    5061                {
    5162                    AVLStack.achFlags[AVLStack.cEntries] = 0; /* 0 first, 1 last */
    52                     AVLStack.aEntries[AVLStack.cEntries++] = pNode->pLeft;
     63                    AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pLeft);
    5364                    continue;
    5465                }
     
    5667
    5768            /* center */
    58             rc = pfnCallBack(pNode, pvParam);
    59             if (rc != 0)
    60             {
    61                 KLOGEXIT(rc);
     69            rc = pfnCallBack(pNode, pvUser);
     70            if (rc)
    6271                return rc;
    63             }
    6472
    6573            /* right */
    6674            AVLStack.cEntries--;
    67             if (pNode->pRight != NULL)
     75            if (pNode->pRight != KAVL_NULL)
    6876            {
    6977                AVLStack.achFlags[AVLStack.cEntries] = 0;
    70                 AVLStack.aEntries[AVLStack.cEntries++] = pNode->pRight;
     78                AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pRight);
    7179            }
    7280        } /* while */
     
    8290            if (!AVLStack.achFlags[AVLStack.cEntries - 1]++)
    8391            {
    84                 if (pNode->pRight != NULL)
     92                if (pNode->pRight != KAVL_NULL)
    8593                {
    8694                    AVLStack.achFlags[AVLStack.cEntries] = 0;  /* 0 first, 1 last */
    87                     AVLStack.aEntries[AVLStack.cEntries++] = pNode->pRight;
     95                    AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pRight);
    8896                    continue;
    8997                }
     
    9199
    92100            /* center */
    93             rc = pfnCallBack(pNode, pvParam);
    94             if (rc != 0)
    95             {
    96                 KLOGEXIT(rc);
     101            rc = pfnCallBack(pNode, pvUser);
     102            if (rc)
    97103                return rc;
    98             }
    99104
    100105            /* left */
    101106            AVLStack.cEntries--;
    102             if (pNode->pLeft != NULL)
     107            if (pNode->pLeft != KAVL_NULL)
    103108            {
    104109                AVLStack.achFlags[AVLStack.cEntries] = 0;
    105                 AVLStack.aEntries[AVLStack.cEntries++] = pNode->pLeft;
     110                AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pLeft);
    106111            }
    107112        } /* while */
    108113    }
    109114
    110     KLOGEXIT(0);
    111115    return 0;
    112116}
    113117
    114 
    115 #endif
    116 
Note: See TracChangeset for help on using the changeset viewer.