VirtualBox

Changeset 7 in kStuff for trunk/include/k/kAvlTmpl/kAvlRemove2.h


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/kAvlRemove2.h

    r2 r7  
    3737 *
    3838 * @returns Pointer to the removed node (NULL if not in the tree)
    39  * @param   ppTree      Pointer to Pointer to the tree root node.
     39 * @param   pRoot       Pointer to the AVL-tree root structure.
    4040 * @param   Key         The Key of which is to be found a best fitting match for..
    4141 *
     
    4343 *          easier to manage.
    4444 */
    45 KAVL_DECL(KAVLNODE *) KAVL_FN(Remove2)(KAVLTREEPTR *ppTree, KAVLNODE *pNode)
     45KAVL_DECL(KAVLNODE *) KAVL_FN(Remove2)(KAVLTROOT *pRoot, KAVLNODE *pNode)
    4646{
    4747#ifdef KAVL_EQUAL_ALLOWED
     
    5050     */
    5151    KAVLNODE *pParent;
    52     KAVLNODE *pCurNode = KAVL_FN(GetWithParent)(ppTree, pNode->mKey, &pParent);
     52    KAVLNODE *pCurNode = KAVL_FN(GetWithParent)(pRoot, pNode->mKey, &pParent);
    5353    if (!pCurNode)
    5454        return NULL;
     55    KAVL_WRITE_LOCK(pRoot); /** @todo the locking here isn't 100% sane. The only way to archive that is by no calling worker functions. */
    5556    if (pCurNode != pNode)
    5657    {
     
    6566                KAVL_SET_POINTER_NULL(&pCurNode->mpList, KAVL_GET_POINTER_NULL(&pNode->mpList));
    6667                pNode->mpList = KAVL_NULL;
     68                KAVL_LOOKTHRU_INVALIDATE_NODE(pRoot, pNode, pNode->mKey);
     69                KAVL_WRITE_UNLOCK(pRoot);
    6770                return pNode;
    6871            }
    6972            pCurNode = pNext;
    7073        }
     74        KAVL_WRITE_UNLOCK(pRoot);
    7175        return NULL;
    7276    }
     
    8084     */
    8185    if (pNode->mpList == KAVL_NODE)
    82         KAVL_FN(Remove)(ppTree, pNode->mKey);
     86    {
     87        KAVL_WRITE_UNLOCK(pRoot);
     88        KAVL_FN(Remove)(pRoot, pNode->mKey);
     89    }
    8390    else
    8491    {
     
    105112        }
    106113        else
    107             KAVL_SET_POINTER(ppTree, pNewUs);
     114            KAVL_SET_POINTER(&pRoot->mpRoot, pNewUs);
     115
     116        KAVL_LOOKTHRU_INVALIDATE_NODE(pRoot, pNode, pNode->mKey);
     117        KAVL_WRITE_UNLOCK(pRoot);
    108118    }
     119
    109120    return pNode;
    110121
     
    116127     * of wrong nodes but just uses this API for his convenience.
    117128     */
    118     KAVLNODE *pRemovedNode = KAVL_FN(Remove)(ppTree, pNode->mKey);
     129    KAVLNODE *pRemovedNode = KAVL_FN(Remove)(pRoot, pNode->mKey);
    119130    if (pRemovedNode == pNode)
    120131        return pRemovedNode;
    121132
    122     KAVL_FN(Insert)(ppTree, pRemovedNode);
     133    KAVL_FN(Insert)(pRoot, pRemovedNode);
    123134    return NULL;
    124135#endif
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