VirtualBox

Changeset 7 in kStuff for trunk/include/k/kAvlTmpl/kAvlEnum.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/kAvlEnum.h

    r2 r7  
    5151
    5252/**
     53 * Ends an enumeration.
     54 *
     55 * The purpose of this function is to unlock the tree should the
     56 * AVL implementation include locking. It's good practice to call
     57 * it anyway even if the tree doesn't do any locking.
     58 *
     59 * @param   pEnumData   Pointer to enumeration control data.
     60 */
     61KAVL_DECL(void) KAVL_FN(EndEnum)(KAVL_TYPE(,ENUMDATA) *pEnumData)
     62{
     63    KAVLROOT pRoot = pEnumData->pRoot;
     64    pEnumData->pRoot = NULL;
     65    if (pRoot)
     66        KAVL_READ_UNLOCK(pEnumData->pRoot);
     67}
     68
     69
     70/**
    5371 * Get the next node in the tree enumeration.
    5472 *
     
    5674 * chain like the DoWithAll function does. This may be changed later.
    5775 *
    58  * @returns Pointer to the first node in the tree.
     76 * @returns Pointer to the next node in the tree.
     77 *          NULL is returned when the end of the tree has been reached,
     78 *          it is not necessary to call EndEnum in this case.
    5979 * @param   pEnumData   Pointer to enumeration control data.
    6080 */
     
    130150    }
    131151
     152    /*
     153     * Call EndEnum.
     154     */
     155    KAVL_FN(EndEnum)(pEnumData);
    132156    return NULL;
    133157}
     
    137161 * Starts an enumeration of all nodes in the given AVL tree.
    138162 *
    139  * The current implementation of this function willl not walk the mpList
     163 * The current implementation of this function will not walk the mpList
    140164 * chain like the DoWithAll function does. This may be changed later.
    141165 *
    142166 * @returns Pointer to the first node in the enumeration.
    143  * @param   ppTree      Pointer to the AVL-tree root node pointer.
    144  * @param   pEnumData   Pointer to enumeration control data.
    145  * @param   fFromLeft   K_TRUE:  Left to right.
    146  *                      K_FALSE: Right to left.
     167 *          If NULL is returned the tree is empty calling EndEnum isn't
     168 *          strictly necessary (although it will do no harm).
     169 * @param   pRoot           Pointer to the AVL-tree root structure.
     170 * @param   pEnumData       Pointer to enumeration control data.
     171 * @param   fFromLeft       K_TRUE:  Left to right.
     172 *                          K_FALSE: Right to left.
    147173 */
    148 KAVL_DECL(KAVLNODE *) KAVL_FN(BeginEnum)(KAVLTREEPTR *ppTree, KAVL_TYPE(,ENUMDATA) *pEnumData, KBOOL fFromLeft)
     174KAVL_DECL(KAVLNODE *) KAVL_FN(BeginEnum)(KAVLROOT *pRoot, KAVL_TYPE(,ENUMDATA) *pEnumData, KBOOL fFromLeft)
    149175{
    150     if (*ppTree != KAVL_NULL)
     176    KAVL_READ_LOCK(pRoot);
     177    pEnumData->pRoot = pRoot;
     178    if (pRoot->mpRoot != KAVL_NULL)
    151179    {
    152180        pEnumData->fFromLeft = fFromLeft;
    153181        pEnumData->cEntries = 1;
    154         pEnumData->aEntries[0] = KAVL_GET_POINTER(ppTree);
     182        pEnumData->aEntries[0] = KAVL_GET_POINTER(pRoot->mpRoot);
    155183        pEnumData->achFlags[0] = 0;
    156184    }
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