Changeset 4687 in vbox for trunk/src/VBox
- Timestamp:
- Sep 11, 2007 9:13:32 AM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r4674 r4687 153 153 table/avlroioport.cpp \ 154 154 table/avlu32.cpp \ 155 table/avllu32.cpp \ 155 156 table/avlul.cpp \ 156 157 table/table.cpp \ -
trunk/src/VBox/Runtime/table/avl_Destroy.cpp.h
r4071 r4687 5 5 6 6 /* 7 * Copyright (C) 1999-200 4knut st. osmundsen ([email protected])7 * Copyright (C) 1999-2007 knut st. osmundsen ([email protected]) 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 22 22 /** 23 * Iterates thru all nodes in the given tree so the caller can free resources 24 * associated with each node. 23 * Destroys the specified tree, starting with the root node and working our way down. 25 24 * 26 * @returns 27 * @returns Return code from the callback on failure. The tree might be half28 * destroyed at this point and will not behave correctly when any29 * insert or remove operation is attempted.30 * 31 * @param 32 * @param 33 * @param pvParamUser parameter passed on to the callback function.25 * @returns 0 on success. 26 * @returns Return value from callback on failure. On failure, the tree will be in 27 * an unbalanced condition and only further calls to the Destroy should be 28 * made on it. Note that the node we fail on will be considered dead and 29 * no action is taken to link it back into the tree. 30 * @param ppTree Pointer to the AVL-tree root node pointer. 31 * @param pfnCallBack Pointer to callback function. 32 * @param pvUser User parameter passed on to the callback function. 34 33 */ 35 RTDECL(int) KAVL_FN(Destroy)(PPKAVLNODECORE ppTree, PKAVLCALLBACK pfnCallBack, void *pv Param)34 RTDECL(int) KAVL_FN(Destroy)(PPKAVLNODECORE ppTree, PKAVLCALLBACK pfnCallBack, void *pvUser) 36 35 { 37 KAVLSTACK2 AVLStack; 36 unsigned cEntries; 37 PKAVLNODECORE apEntries[KAVL_MAX_STACK]; 38 int rc; 39 38 40 if (*ppTree == KAVL_NULL) 39 41 return 0; 40 42 41 AVLStack.cEntries = 1; 42 AVLStack.achFlags[0] = 0; 43 AVLStack.aEntries[0] = KAVL_GET_POINTER(ppTree); 44 while (AVLStack.cEntries > 0) 43 cEntries = 1; 44 apEntries[0] = KAVL_GET_POINTER(ppTree); 45 while (cEntries > 0) 45 46 { 46 int rc; 47 PKAVLNODECORE pNode = AVLStack.aEntries[AVLStack.cEntries - 1]; 47 /* 48 * Process the subtrees first. 49 */ 50 PKAVLNODECORE pNode = apEntries[cEntries - 1]; 51 if (pNode->pLeft != KAVL_NULL) 52 apEntries[cEntries++] = KAVL_GET_POINTER(&pNode->pLeft); 53 else if (pNode->pRight != KAVL_NULL) 54 apEntries[cEntries++] = KAVL_GET_POINTER(&pNode->pRight); 55 else 56 { 57 #ifdef KAVL_EQUAL_ALLOWED 58 /* 59 * Process nodes with the same key. 60 */ 61 while (pNode->pList != KAVL_NULL) 62 { 63 PKAVLNODECORE pEqual = KAVL_GET_POINTER(&pNode->pList); 64 KAVL_SET_POINTER(&pNode->pList, KAVL_GET_POINTER_NULL(&pEqual->pList)); 65 pEqual->pList = KAVL_NULL; 48 66 49 if (!AVLStack.achFlags[AVLStack.cEntries - 1]++) 50 { 51 /* push left and recurse */ 52 if (pNode->pLeft != KAVL_NULL) 67 rc = pfnCallBack(pEqual, pvUser); 68 if (rc) 69 return rc; 70 } 71 #endif 72 73 /* 74 * Unlink the node. 75 */ 76 if (--cEntries > 0) 53 77 { 54 AVLStack.achFlags[AVLStack.cEntries] = 0; /* 0 first, 1 last */ 55 AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pLeft); 56 continue; 78 PKAVLNODECORE pParent = apEntries[cEntries - 1]; 79 if (KAVL_GET_POINTER(&pParent->pLeft) == pNode) 80 pParent->pLeft = KAVL_NULL; 81 else 82 pParent->pRight = KAVL_NULL; 57 83 } 84 else 85 *ppTree = KAVL_NULL; 86 87 kASSERT(pNode->pLeft == KAVL_NULL); 88 kASSERT(pNode->pRight == KAVL_NULL); 89 rc = pfnCallBack(pNode, pvUser); 90 if (rc) 91 return rc; 58 92 } 59 60 /* pop pNode */61 AVLStack.cEntries--;62 63 /* push right */64 if (pNode->pRight != KAVL_NULL)65 {66 AVLStack.achFlags[AVLStack.cEntries] = 0;67 AVLStack.aEntries[AVLStack.cEntries++] = KAVL_GET_POINTER(&pNode->pRight);68 }69 70 /* call destructor */71 pNode->pRight = pNode->pLeft = KAVL_NULL;72 rc = pfnCallBack(pNode, pvParam);73 if (rc)74 return rc;75 76 93 } /* while */ 77 94 78 *ppTree = KAVL_NULL; 95 kASSERT(*ppTree == KAVL_NULL); 96 79 97 return 0; 80 98 } 81 82 99 83 100 #endif -
trunk/src/VBox/Runtime/table/avl_DoWithAll.cpp.h
r4071 r4687 5 5 6 6 /* 7 * Copyright (C) 1999-200 2knut st. osmundsen ([email protected])7 * Copyright (C) 1999-2007 knut st. osmundsen ([email protected]) 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 22 22 /** 23 * Iterates t ru all nodes in the given tree.23 * Iterates thru all nodes in the given tree. 24 24 * @returns 0 on success. Return from callback on failure. 25 25 * @param ppTree Pointer to the AVL-tree root node pointer. … … 33 33 KAVLSTACK2 AVLStack; 34 34 PKAVLNODECORE pNode; 35 #ifdef KAVL_EQUAL_ALLOWED 36 PKAVLNODECORE pEqual; 37 #endif 35 38 int rc; 36 39 … … 63 66 if (rc) 64 67 return rc; 68 #ifdef KAVL_EQUAL_ALLOWED 69 if (pNode->pList != KAVL_NULL) 70 for (pEqual = KAVL_GET_POINTER(&pNode->pList); pEqual; pEqual = KAVL_GET_POINTER_NULL(&pEqual->pList)) 71 { 72 rc = pfnCallBack(pEqual, pvParam); 73 if (rc) 74 return rc; 75 } 76 #endif 65 77 66 78 /* right */ … … 79 91 pNode = AVLStack.aEntries[AVLStack.cEntries - 1]; 80 92 81 82 93 /* right */ 83 94 if (!AVLStack.achFlags[AVLStack.cEntries - 1]++) … … 95 106 if (rc) 96 107 return rc; 108 #ifdef KAVL_EQUAL_ALLOWED 109 if (pNode->pList != KAVL_NULL) 110 for (pEqual = KAVL_GET_POINTER(&pNode->pList); pEqual; pEqual = KAVL_GET_POINTER_NULL(&pEqual->pList)) 111 { 112 rc = pfnCallBack(pEqual, pvParam); 113 if (rc) 114 return rc; 115 } 116 #endif 97 117 98 118 /* left */ -
trunk/src/VBox/Runtime/table/avl_RemoveBestFit.cpp.h
r4071 r4687 45 45 if (pNode != NULL) 46 46 { 47 47 #ifdef KAVL_EQUAL_ALLOWED 48 48 if (pNode->pList != KAVL_NULL) 49 49 { 50 PKAVL ANODECORE pRet = KAVL_GET_POINTER(&pNode->pList);50 PKAVLNODECORE pRet = KAVL_GET_POINTER(&pNode->pList); 51 51 KAVL_SET_POINTER_NULL(&pNode->pList, &pRet->pList); 52 52 return pRet; 53 53 } 54 54 #endif 55 55 pNode = KAVL_FN(Remove)(ppTree, pNode->Key); 56 56 } -
trunk/src/VBox/Runtime/table/avllu32.cpp
r4612 r4687 26 26 * AVL configuration. 27 27 */ 28 #define KAVL_FN(a) RTAvl U32##a28 #define KAVL_FN(a) RTAvllU32##a 29 29 #define KAVL_MAX_STACK 27 /* Up to 2^24 nodes. */ 30 #define KAVL_ CHECK_FOR_EQUAL_INSERT 1 /* Noduplicate keys! */31 #define KAVLNODECORE AVL U32NODECORE32 #define PKAVLNODECORE PAVL U32NODECORE33 #define PPKAVLNODECORE PPAVL U32NODECORE34 #define KAVLKEY AVL U32KEY35 #define PKAVLKEY PAVL U32KEY36 #define KAVLENUMDATA AVL U32ENUMDATA37 #define PKAVLENUMDATA PAVL U32ENUMDATA38 #define PKAVLCALLBACK PAVL U32CALLBACK30 #define KAVL_EQUAL_ALLOWED 1 /* List duplicate keys! */ 31 #define KAVLNODECORE AVLLU32NODECORE 32 #define PKAVLNODECORE PAVLLU32NODECORE 33 #define PPKAVLNODECORE PPAVLLU32NODECORE 34 #define KAVLKEY AVLLU32KEY 35 #define PKAVLKEY PAVLLU32KEY 36 #define KAVLENUMDATA AVLLU32ENUMDATA 37 #define PKAVLENUMDATA PAVLLU32ENUMDATA 38 #define PKAVLCALLBACK PAVLLU32CALLBACK 39 39 40 40
Note:
See TracChangeset
for help on using the changeset viewer.