VirtualBox

Ignore:
Timestamp:
Feb 4, 2008 2:08:02 AM (17 years ago)
Author:
bird
Message:

kAVL: Implemented locking, root node and a direct cache.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/k/kAvlTmpl/kAvlGetBestFit.h

    r2 r7  
    3737 *
    3838 * @returns Pointer to the best fitting node found.
    39  * @param   ppTree      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.
    4343 * @sketch  The best fitting node is always located in the searchpath above you.
    4444 *          >= (above): The node where you last turned left.
    4545 *          <= (below): the node where you last turned right.
    4646 */
    47 KAVL_DECL(KAVLNODE *) KAVL_FN(GetBestFit)(KAVLTREEPTR *ppTree, KAVLKEY Key, KBOOL fAbove)
     47KAVL_DECL(KAVLNODE *) KAVL_FN(GetBestFit)(KAVLROOT *pRoot, KAVLKEY Key, KBOOL fAbove)
    4848{
    4949    register KAVLNODE  *pNode;
    5050    KAVLNODE           *pNodeLast;
    5151
    52     if (*ppTree == KAVL_NULL)
     52    KAVL_READ_LOCK(pLook);
     53    if (pRoot->mpRoot == KAVL_NULL)
     54    {
     55        KAVL_READ_UNLOCK(pLook);
    5356        return NULL;
     57    }
    5458
    55     pNode = KAVL_GET_POINTER(ppTree);
     59    pNode = KAVL_GET_POINTER(&pRoot->mpRoot);
    5660    pNodeLast = NULL;
    5761    if (fAbove)
     
    6266            {
    6367                if (pNode->mpLeft == KAVL_NULL)
     68                {
     69                    KAVL_READ_UNLOCK(pLook);
    6470                    return pNode;
     71                }
    6572                pNodeLast = pNode;
    6673                pNode = KAVL_GET_POINTER(&pNode->mpLeft);
     
    6976            {
    7077                if (pNode->mpRight == KAVL_NULL)
     78                {
     79                    KAVL_READ_UNLOCK(pLook);
    7180                    return pNodeLast;
     81                }
    7282                pNode = KAVL_GET_POINTER(&pNode->mpRight);
    7383            }
     
    8191            {
    8292                if (pNode->mpLeft == KAVL_NULL)
     93                {
     94                    KAVL_READ_UNLOCK(pLook);
    8395                    return pNodeLast;
     96                }
    8497                pNode = KAVL_GET_POINTER(&pNode->mpLeft);
    8598            }
     
    87100            {
    88101                if (pNode->mpRight == KAVL_NULL)
     102                {
     103                    KAVL_READ_UNLOCK(pLook);
    89104                    return pNode;
     105                }
    90106                pNodeLast = pNode;
    91107                pNode = KAVL_GET_POINTER(&pNode->mpRight);
     
    95111
    96112    /* perfect match or nothing. */
     113    KAVL_READ_UNLOCK(pLook);
    97114    return pNode;
    98115}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette