Changeset 3555 for trunk/kStuff/include/k/kAVLTmpl/kAVLDoWithAll.h
- Timestamp:
- Aug 26, 2007, 12:43:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/include/k/kAVLTmpl/kAVLDoWithAll.h
r3553 r3555 1 1 /* $Id$ */ 2 2 /** @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. 9 4 */ 10 5 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 */ 13 26 14 27 15 28 /** 16 29 * 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. 21 35 * @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. 25 37 */ 26 unsigned KLIBCALL KAVL_FN(DoWithAll)(PPKAVLNODECORE ppTree, int fFromLeft, PKAVLCALLBACK pfnCallBack, void * pvParam)38 KAVL_DECL(int) KAVL_FN(DoWithAll)(KAVLTREEPTR *ppTree, KBOOL fFromLeft, KAVL_TYPE(PFN,CALLBACK) pfnCallBack, void *pvUser) 27 39 { 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; 32 43 33 if (*ppTree == NULL)44 if (*ppTree == KAVL_NULL) 34 45 return 0; 35 46 36 47 AVLStack.cEntries = 1; 37 48 AVLStack.achFlags[0] = 0; 38 AVLStack.aEntries[0] = *ppTree;49 AVLStack.aEntries[0] = KAVL_GET_POINTER(ppTree); 39 50 40 51 if (fFromLeft) … … 47 58 if (!AVLStack.achFlags[AVLStack.cEntries - 1]++) 48 59 { 49 if (pNode->pLeft != NULL)60 if (pNode->pLeft != KAVL_NULL) 50 61 { 51 62 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); 53 64 continue; 54 65 } … … 56 67 57 68 /* center */ 58 rc = pfnCallBack(pNode, pvParam); 59 if (rc != 0) 60 { 61 KLOGEXIT(rc); 69 rc = pfnCallBack(pNode, pvUser); 70 if (rc) 62 71 return rc; 63 }64 72 65 73 /* right */ 66 74 AVLStack.cEntries--; 67 if (pNode->pRight != NULL)75 if (pNode->pRight != KAVL_NULL) 68 76 { 69 77 AVLStack.achFlags[AVLStack.cEntries] = 0; 70 AVLStack.aEntries[AVLStack.cEntries++] = pNode->pRight;78 AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pRight); 71 79 } 72 80 } /* while */ … … 82 90 if (!AVLStack.achFlags[AVLStack.cEntries - 1]++) 83 91 { 84 if (pNode->pRight != NULL)92 if (pNode->pRight != KAVL_NULL) 85 93 { 86 94 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); 88 96 continue; 89 97 } … … 91 99 92 100 /* center */ 93 rc = pfnCallBack(pNode, pvParam); 94 if (rc != 0) 95 { 96 KLOGEXIT(rc); 101 rc = pfnCallBack(pNode, pvUser); 102 if (rc) 97 103 return rc; 98 }99 104 100 105 /* left */ 101 106 AVLStack.cEntries--; 102 if (pNode->pLeft != NULL)107 if (pNode->pLeft != KAVL_NULL) 103 108 { 104 109 AVLStack.achFlags[AVLStack.cEntries] = 0; 105 AVLStack.aEntries[AVLStack.cEntries++] = pNode->pLeft;110 AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pLeft); 106 111 } 107 112 } /* while */ 108 113 } 109 114 110 KLOGEXIT(0);111 115 return 0; 112 116 } 113 117 114 115 #endif116
Note:
See TracChangeset
for help on using the changeset viewer.