Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / search / twalk.c
blob7aec6e4dd24ef639a7eada24b7a08dcf5276ba74
1 /* $NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $ */
3 /*
4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5 * the AT&T man page says.
7 * The node_t structure is for internal use only, lint doesn't grok it.
9 * Written by reading the System V Interface Definition, not the code.
11 * Totally public domain.
14 #include <sys/cdefs.h>
15 #if 0
16 #if defined(LIBC_SCCS) && !defined(lint)
17 __RCSID("$NetBSD: twalk.c,v 1.1 1999/02/22 10:33:16 christos Exp $");
18 #endif /* LIBC_SCCS and not lint */
19 #endif
21 #include <assert.h>
22 #define _SEARCH_PRIVATE
23 #include <search.h>
24 #include <stdlib.h>
26 static void trecurse(const node_t *,
27 void (*action)(const void *, VISIT, int), int level);
29 /* Walk the nodes of a tree */
30 static void
31 trecurse(
32 const node_t *root, /* Root of the tree to be walked */
33 void (*action)(const void *, VISIT, int),
34 int level
38 if (root->llink == NULL && root->rlink == NULL)
39 (*action)(root, leaf, level);
40 else {
41 (*action)(root, preorder, level);
42 if (root->llink != NULL)
43 trecurse(root->llink, action, level + 1);
44 (*action)(root, postorder, level);
45 if (root->rlink != NULL)
46 trecurse(root->rlink, action, level + 1);
47 (*action)(root, endorder, level);
51 /* Walk the nodes of a tree */
52 void
53 twalk (const void *vroot, /* Root of the tree to be walked */
54 void (*action)(const void *, VISIT, int))
56 if (vroot != NULL && action != NULL)
57 trecurse(vroot, action, 0);