Rev 2503 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2503 | Rev 2504 | ||
---|---|---|---|
Line 683... | Line 683... | ||
683 | avltree_delete(t, node); |
683 | avltree_delete(t, node); |
684 | 684 | ||
685 | return true; |
685 | return true; |
686 | } |
686 | } |
687 | 687 | ||
- | 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 | */ |
|
688 | static void _avltree_walk(avltree_node_t *node, avltree_walker_t walker) |
699 | static bool _avltree_walk(avltree_node_t *node, avltree_walker_t walker, |
- | 700 | void *arg) |
|
689 | { |
701 | { |
690 | if (node->lft) |
702 | if (node->lft) { |
691 | _avltree_walk(node->lft, walker); |
703 | if (!_avltree_walk(node->lft, walker, arg)) |
- | 704 | return false; |
|
- | 705 | } |
|
692 | walker(node); |
706 | if (!walker(node, arg)) |
- | 707 | return false; |
|
693 | if (node->rgt) |
708 | if (node->rgt) { |
694 | _avltree_walk(node->rgt, walker); |
709 | if (!_avltree_walk(node->rgt, walker, arg)) |
- | 710 | return false; |
|
- | 711 | } |
|
- | 712 | return true; |
|
695 | } |
713 | } |
696 | 714 | ||
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. |
|
698 | * |
717 | * |
699 | * @param t AVL tree to be walked. |
718 | * @param t AVL tree to be walked. |
700 | * @param walker Walker function that will be called on each visited |
719 | * @param walker Walker function that will be called on each visited |
701 | * node. |
720 | * node. |
- | 721 | * @param arg Argument for the walker. |
|
702 | */ |
722 | */ |
703 | void avltree_walk(avltree_t *t, avltree_walker_t walker) |
723 | void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg) |
704 | { |
724 | { |
705 | _avltree_walk(t->root, walker); |
725 | _avltree_walk(t->root, walker, arg); |
706 | } |
726 | } |
707 | 727 | ||
708 | /** @} |
728 | /** @} |
709 | */ |
729 | */ |
710 | 730 |