Changeset 7 in kStuff for trunk/include/k/kAvlTmpl/kAvlGet.h
- Timestamp:
- Feb 4, 2008 2:08:02 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/include/k/kAvlTmpl/kAvlGet.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/k/kAvlTmpl/kAvlGet.h
r2 r7 36 36 * Gets a node from the tree (does not remove it!) 37 37 * 38 * @returns Pointer to the node holding the given key.39 * @param ppTree Pointer to the AVL-tree root node pointer.40 * @param KeyKey value of the node which is to be found.38 * @returns Pointer to the node holding the given key. 39 * @param pRoot Pointer to the AVL-tree root structure. 40 * @param Key Key value of the node which is to be found. 41 41 */ 42 KAVL_DECL(KAVLNODE *) KAVL_FN(Get)(KAVL TREEPTR *ppTree, KAVLKEY Key)42 KAVL_DECL(KAVLNODE *) KAVL_FN(Get)(KAVLROOT *pRoot, KAVLKEY Key) 43 43 { 44 44 KAVLNODE *pNode; 45 if (*ppTree == KAVL_NULL) 45 #ifdef KAVL_LOOKTHRU_CACHE 46 KAVLTREEPTR *ppEntry; 47 #endif 48 49 KAVL_READ_LOCK(pRoot); 50 if (pRoot->mpRoot == KAVL_NULL) 51 { 52 KAVL_READ_UNLOCK(pRoot); 46 53 return NULL; 54 } 47 55 48 pNode = KAVL_GET_POINTER(ppTree); 49 while (KAVL_NE(pNode->mKey, Key)) 56 #ifdef KAVL_LOOKTHRU_CACHE 57 ppEntry = &pRoot->maLookthru[KAVL_LOOKTHRU_HASH(Key)]; 58 pNode = KAVL_GET_POINTER_NULL(ppEntry); 59 if (!pNode || KAVL_NE(pNode->mKey, Key)) 60 #endif 50 61 { 51 if (KAVL_G(pNode->mKey, Key)) 62 pNode = KAVL_GET_POINTER(&pRoot->mpRoot); 63 while (KAVL_NE(pNode->mKey, Key)) 52 64 { 53 if (pNode->mpLeft == KAVL_NULL) 54 return NULL; 55 pNode = KAVL_GET_POINTER(&pNode->mpLeft); 65 if (KAVL_G(pNode->mKey, Key)) 66 { 67 if (pNode->mpLeft == KAVL_NULL) 68 { 69 KAVL_READ_UNLOCK(pRoot); 70 return NULL; 71 } 72 pNode = KAVL_GET_POINTER(&pNode->mpLeft); 73 } 74 else 75 { 76 if (pNode->mpRight == KAVL_NULL) 77 { 78 KAVL_READ_UNLOCK(pRoot); 79 return NULL; 80 } 81 pNode = KAVL_GET_POINTER(&pNode->mpRight); 82 } 56 83 } 57 else 58 { 59 if (pNode->mpRight == KAVL_NULL) 60 return NULL; 61 pNode = KAVL_GET_POINTER(&pNode->mpRight); 62 } 84 85 #ifdef KAVL_LOOKTHRU_CACHE 86 KAVL_SET_POINTER(ppEntry, pNode); 87 #endif 63 88 } 89 90 KAVL_READ_UNLOCK(pRoot); 64 91 return pNode; 65 92 }
Note:
See TracChangeset
for help on using the changeset viewer.

