Network - redispatch was not properly adjust ip->ip_len
[dragonfly.git] / lib / libc / stdlib / twalk.c
blobcb480180c0b908a74ef77a0926370dc12439d614
1 /*
2 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
3 * the AT&T man page says.
5 * The node_t structure is for internal use only, lint doesn't grok it.
7 * Written by reading the System V Interface Definition, not the code.
9 * Totally public domain.
11 * $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $
12 * $FreeBSD: src/lib/libc/stdlib/twalk.c,v 1.5 2003/01/05 02:43:18 tjr Exp $
13 * $DragonFly: src/lib/libc/stdlib/twalk.c,v 1.5 2005/11/24 17:18:30 swildner Exp $
16 #define _SEARCH_PRIVATE
17 #include <search.h>
18 #include <stdlib.h>
20 static void trecurse(const node_t *,
21 void (*action)(const void *, VISIT, int), int level);
24 * Walk the nodes of a tree
26 * Parameters:
27 * root: Root of the tree to be walked
29 static void
30 trecurse(const node_t *root, void (*action)(const void *, VISIT, int),
31 int level)
34 if (root->llink == NULL && root->rlink == NULL)
35 (*action)(root, leaf, level);
36 else {
37 (*action)(root, preorder, level);
38 if (root->llink != NULL)
39 trecurse(root->llink, action, level + 1);
40 (*action)(root, postorder, level);
41 if (root->rlink != NULL)
42 trecurse(root->rlink, action, level + 1);
43 (*action)(root, endorder, level);
48 * Walk the nodes of a tree
50 * Parameters:
51 * vroot: Root of the tree to be walked
53 void
54 twalk(const void *vroot,
55 void (*action)(const void *, VISIT, int))
57 if (vroot != NULL && action != NULL)
58 trecurse(vroot, action, 0);