Changeset 7 in kStuff for trunk/include/k/kAvlTmpl/kAvlGetBestFit.h
- Timestamp:
- Feb 4, 2008 2:08:02 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/include/k/kAvlTmpl/kAvlGetBestFit.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/k/kAvlTmpl/kAvlGetBestFit.h
r2 r7 37 37 * 38 38 * @returns Pointer to the best fitting node found. 39 * @param p pTree Pointer to Pointer to the tree root node.40 * @param Key The Key of which is to be found a best fitting match for..41 * @param fAbove K_TRUE: Returned node is have the closest key to Key from above.42 * K_FALSE: Returned node is have the closest key to Key from below.39 * @param pRoot Pointer to the AVL-tree root structure. 40 * @param Key The Key of which is to be found a best fitting match for.. 41 * @param fAbove K_TRUE: Returned node is have the closest key to Key from above. 42 * K_FALSE: Returned node is have the closest key to Key from below. 43 43 * @sketch The best fitting node is always located in the searchpath above you. 44 44 * >= (above): The node where you last turned left. 45 45 * <= (below): the node where you last turned right. 46 46 */ 47 KAVL_DECL(KAVLNODE *) KAVL_FN(GetBestFit)(KAVL TREEPTR *ppTree, KAVLKEY Key, KBOOL fAbove)47 KAVL_DECL(KAVLNODE *) KAVL_FN(GetBestFit)(KAVLROOT *pRoot, KAVLKEY Key, KBOOL fAbove) 48 48 { 49 49 register KAVLNODE *pNode; 50 50 KAVLNODE *pNodeLast; 51 51 52 if (*ppTree == KAVL_NULL) 52 KAVL_READ_LOCK(pLook); 53 if (pRoot->mpRoot == KAVL_NULL) 54 { 55 KAVL_READ_UNLOCK(pLook); 53 56 return NULL; 57 } 54 58 55 pNode = KAVL_GET_POINTER( ppTree);59 pNode = KAVL_GET_POINTER(&pRoot->mpRoot); 56 60 pNodeLast = NULL; 57 61 if (fAbove) … … 62 66 { 63 67 if (pNode->mpLeft == KAVL_NULL) 68 { 69 KAVL_READ_UNLOCK(pLook); 64 70 return pNode; 71 } 65 72 pNodeLast = pNode; 66 73 pNode = KAVL_GET_POINTER(&pNode->mpLeft); … … 69 76 { 70 77 if (pNode->mpRight == KAVL_NULL) 78 { 79 KAVL_READ_UNLOCK(pLook); 71 80 return pNodeLast; 81 } 72 82 pNode = KAVL_GET_POINTER(&pNode->mpRight); 73 83 } … … 81 91 { 82 92 if (pNode->mpLeft == KAVL_NULL) 93 { 94 KAVL_READ_UNLOCK(pLook); 83 95 return pNodeLast; 96 } 84 97 pNode = KAVL_GET_POINTER(&pNode->mpLeft); 85 98 } … … 87 100 { 88 101 if (pNode->mpRight == KAVL_NULL) 102 { 103 KAVL_READ_UNLOCK(pLook); 89 104 return pNode; 105 } 90 106 pNodeLast = pNode; 91 107 pNode = KAVL_GET_POINTER(&pNode->mpRight); … … 95 111 96 112 /* perfect match or nothing. */ 113 KAVL_READ_UNLOCK(pLook); 97 114 return pNode; 98 115 }
Note:
See TracChangeset
for help on using the changeset viewer.

