Changeset 3555 for trunk/kStuff/include/k/kAVLTmpl/kAVLEnum.h
- Timestamp:
- Aug 26, 2007, 12:43:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/include/k/kAVLTmpl/kAVLEnum.h
r3553 r3555 1 1 /* $Id$ */ 2 2 /** @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. 9 4 */ 10 5 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 * 24 25 */ 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 else37 pEnumData->cEntries = 0;38 39 pNode = KAVL_FN(GetNextNode)(pEnumData);40 KLOGEXIT(pNode);41 return pNode;42 }43 44 26 45 27 /** … … 50 32 * @author knut st. osmundsen 51 33 */ 52 PKAVLNODECORE KLIBCALL KAVL_FN(GetNextNode)(PKAVLENUMDATApEnumData)34 KAVL_DECL(KAVLNODECORE *) KAVL_FN(GetNextNode)(KAVL_TYPE(,ENUMDATA) *pEnumData) 53 35 { 54 KLOGENTRY1("PKAVLNODECORE","PKAVLENUMDATA pEnumData", pEnumData);55 PKAVLNODECORE pNode;56 57 36 if (pEnumData->fFromLeft) 58 37 { /* from left */ 59 38 while (pEnumData->cEntries > 0) 60 39 { 61 pNode = pEnumData->aEntries[pEnumData->cEntries - 1];40 KAVLNODECORE *pNode = pEnumData->aEntries[pEnumData->cEntries - 1]; 62 41 63 42 /* left */ … … 65 44 { 66 45 pEnumData->achFlags[pEnumData->cEntries - 1]++; 67 if (pNode->pLeft != NULL)46 if (pNode->pLeft != KAVL_NULL) 68 47 { 69 48 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); 71 50 continue; 72 51 } … … 77 56 { 78 57 pEnumData->achFlags[pEnumData->cEntries - 1]++; 79 KLOGEXIT(pNode);80 58 return pNode; 81 59 } … … 83 61 /* right */ 84 62 pEnumData->cEntries--; 85 if (pNode->pRight != NULL)63 if (pNode->pRight != KAVL_NULL) 86 64 { 87 65 pEnumData->achFlags[pEnumData->cEntries] = 0; 88 pEnumData->aEntries[pEnumData->cEntries++] = pNode->pRight;66 pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pRight); 89 67 } 90 68 } /* while */ … … 94 72 while (pEnumData->cEntries > 0) 95 73 { 96 pNode = pEnumData->aEntries[pEnumData->cEntries - 1]; 97 74 KAVLNODECORE *pNode = pEnumData->aEntries[pEnumData->cEntries - 1]; 98 75 99 76 /* right */ … … 101 78 { 102 79 pEnumData->achFlags[pEnumData->cEntries - 1]++; 103 if (pNode->pRight != NULL)80 if (pNode->pRight != KAVL_NULL) 104 81 { 105 82 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); 107 84 continue; 108 85 } … … 113 90 { 114 91 pEnumData->achFlags[pEnumData->cEntries - 1]++; 115 KLOGEXIT(pNode);116 92 return pNode; 117 93 } … … 119 95 /* left */ 120 96 pEnumData->cEntries--; 121 if (pNode->pLeft != NULL)97 if (pNode->pLeft != KAVL_NULL) 122 98 { 123 99 pEnumData->achFlags[pEnumData->cEntries] = 0; 124 pEnumData->aEntries[pEnumData->cEntries++] = pNode->pLeft;100 pEnumData->aEntries[pEnumData->cEntries++] = KAVL_GET_POINTER(&pNode->pLeft); 125 101 } 126 102 } /* while */ 127 103 } 128 104 129 KLOGEXIT(NULL);130 105 return NULL; 131 106 } 132 107 133 108 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 */ 118 KAVL_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; 135 129 130 return KAVL_FN(GetNextNode)(pEnumData); 131 } 132
Note:
See TracChangeset
for help on using the changeset viewer.