Changeset b76a2217 in mainline for kernel/generic/src/adt/avl.c


Ignore:
Timestamp:
2007-07-29T19:17:25Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7fe9c5b
Parents:
83a5cba
Message:

Give the AVL tree walkers the possibility to take an argument.
Each walker is now supposed to return a bool value to support walk termination.

Switch over from the tasks_btree B+tree to tasks_tree AVL tree.
This makes the fix for ticket #48 complete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/avl.c

    r83a5cba rb76a2217  
    686686}
    687687
    688 static void _avltree_walk(avltree_node_t *node, avltree_walker_t walker)
     688/** Walk a subtree of an AVL tree in-order and apply a supplied walker on each
     689 * visited node.
     690 *
     691 * @param node          Node representing the root of an AVL subtree to be
     692 *                      walked.
     693 * @param walker        Walker function that will be appliad on each visited
     694 *                      node.
     695 * @param arg           Argument for the walker.
     696 *
     697 * @return              Zero if the walk should stop or non-zero otherwise.
     698 */
     699static bool _avltree_walk(avltree_node_t *node, avltree_walker_t walker,
     700    void *arg)
    689701{
    690         if (node->lft)
    691                 _avltree_walk(node->lft, walker);
    692         walker(node);
    693         if (node->rgt)
    694                 _avltree_walk(node->rgt, walker);
     702        if (node->lft) {
     703                if (!_avltree_walk(node->lft, walker, arg))
     704                        return false;
     705        }
     706        if (!walker(node, arg))
     707                return false;
     708        if (node->rgt) {
     709                if (!_avltree_walk(node->rgt, walker, arg))
     710                        return false;
     711        }
     712        return true;
    695713}
    696714
    697 /** Walk the AVL tree and apply the walker function on each visited node.
     715/** Walk the AVL tree in-order and apply the walker function on each visited
     716 * node.
    698717 *
    699718 * @param t             AVL tree to be walked.
    700719 * @param walker        Walker function that will be called on each visited
    701720 *                      node.
    702  */
    703 void avltree_walk(avltree_t *t, avltree_walker_t walker)
     721 * @param arg           Argument for the walker.
     722 */
     723void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg)
    704724{
    705         _avltree_walk(t->root, walker);
     725        _avltree_walk(t->root, walker, arg);
    706726}
    707727
Note: See TracChangeset for help on using the changeset viewer.