diff options
| author | millert <> | 1997-06-15 23:59:33 +0000 |
|---|---|---|
| committer | millert <> | 1997-06-15 23:59:33 +0000 |
| commit | b53bdf3713e15f07006d834df512853036edfb2f (patch) | |
| tree | 25f766b1fe2e96cf3f670c4de839dfcc2b6ff803 /src/lib/libc/stdlib | |
| parent | c46b403f381d4c3bc54d886cb431533b8dfee7a0 (diff) | |
| download | openbsd-b53bdf3713e15f07006d834df512853036edfb2f.tar.gz openbsd-b53bdf3713e15f07006d834df512853036edfb2f.tar.bz2 openbsd-b53bdf3713e15f07006d834df512853036edfb2f.zip | |
First cut at documentinf tsearch(3) -- needs work.
Diffstat (limited to 'src/lib/libc/stdlib')
| -rw-r--r-- | src/lib/libc/stdlib/tsearch.3 | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/lib/libc/stdlib/tsearch.3 b/src/lib/libc/stdlib/tsearch.3 new file mode 100644 index 0000000000..09ee1c396d --- /dev/null +++ b/src/lib/libc/stdlib/tsearch.3 | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | .\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 2 | .\" All rights reserved. | ||
| 3 | .\" | ||
| 4 | .\" Redistribution and use in source and binary forms, with or without | ||
| 5 | .\" modification, are permitted provided that the following conditions | ||
| 6 | .\" are met: | ||
| 7 | .\" 1. Redistributions of source code must retain the above copyright | ||
| 8 | .\" notice, this list of conditions and the following disclaimer. | ||
| 9 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | .\" notice, this list of conditions and the following disclaimer in the | ||
| 11 | .\" documentation and/or other materials provided with the distribution. | ||
| 12 | .\" 3. All advertising materials mentioning features or use of this software | ||
| 13 | .\" must display the following acknowledgement: | ||
| 14 | .\" This product includes software developed by Todd C. Miller. | ||
| 15 | .\" 4. The name of the author may not be used to endorse or promote products | ||
| 16 | .\" derived from this software without specific prior written permission. | ||
| 17 | .\" | ||
| 18 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 19 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 20 | .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 21 | .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 | .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 | .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 24 | .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 25 | .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 26 | .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 27 | .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | .\" | ||
| 29 | .\" $OpenBSD: tsearch.3,v 1.1 1997/06/15 23:59:33 millert Exp $ | ||
| 30 | .\" | ||
| 31 | .Dd June 15, 1997 | ||
| 32 | .Dt TSEARCH 3 | ||
| 33 | .Os | ||
| 34 | .Sh NAME | ||
| 35 | .Nm tsearch, tfind, tdelete, twalk | ||
| 36 | .Nd manipulate binary search trees | ||
| 37 | .Sh SYNOPSIS | ||
| 38 | .Fd #include <search.h> | ||
| 39 | .Ft void * | ||
| 40 | .Fn tdelete "const void *key" "void **rootp", "int (*compar) (const void *, const void *)" | ||
| 41 | .Ft void * | ||
| 42 | .Fn tfind "const void *key" "void * const *rootp", "int (*compar) (const void *, const void *)" | ||
| 43 | .Ft void * | ||
| 44 | .Fn tsearch "const void *key" "void **rootp", "int (*compar) (const void *, const void *)" | ||
| 45 | .Ft void | ||
| 46 | .Fn twalk "const void *root" "void (*compar) (const void *, VISIT, int)" | ||
| 47 | .Sh DESCRIPTION | ||
| 48 | The | ||
| 49 | .Fn tdelete , | ||
| 50 | .Fn tfind , | ||
| 51 | .Fn tsearch , | ||
| 52 | and | ||
| 53 | .Fn twalk | ||
| 54 | functions manage binary search trees based on algorithms T and D | ||
| 55 | from Knuth (6.2.2). The comparison function passed in by | ||
| 56 | the user has the same style of return values as | ||
| 57 | .Xr strcmp 3 . | ||
| 58 | .Pp | ||
| 59 | .Fn Tfind | ||
| 60 | searches for the datum matched by the argument | ||
| 61 | .Fa key | ||
| 62 | in the binary tree rooted at | ||
| 63 | .Fa rootp , | ||
| 64 | returning a pointer to the datum if it is found and NULL | ||
| 65 | if it is not. | ||
| 66 | .Pp | ||
| 67 | .Fn Tsearch | ||
| 68 | is identical to | ||
| 69 | .Fn tfind | ||
| 70 | except that if no match is found, | ||
| 71 | .Fa key | ||
| 72 | is inserted into the tree and a pointer to it is returned. If | ||
| 73 | .Fa rootp | ||
| 74 | points to a NULL value a new binary search tree is created. | ||
| 75 | .Pp | ||
| 76 | .Fn Tdelete | ||
| 77 | deletes a node from the specified binary search tree and returns | ||
| 78 | a pointer to the parent of the node to be deleted. | ||
| 79 | It takes the same arguments as | ||
| 80 | .Fn tfind | ||
| 81 | and | ||
| 82 | .Fn tsearch . | ||
| 83 | If the node to be deleted is the root of the binary search tree, | ||
| 84 | .Fa rootp | ||
| 85 | will be adjusted. | ||
| 86 | .Pp | ||
| 87 | .Fn Twalk | ||
| 88 | walks the binary search tree rooted in | ||
| 89 | .fa root | ||
| 90 | and calls the function | ||
| 91 | .Fa action | ||
| 92 | on each node. | ||
| 93 | .Fa Action | ||
| 94 | is called with three arguments: a pointer to the current node, | ||
| 95 | a value from the enum | ||
| 96 | .Sy "typedef enum { preorder, postorder, endorder, leaf } VISIT;" | ||
| 97 | specifying the traversal type, and a node level (where level | ||
| 98 | zero is the root of the tree). | ||
| 99 | .Sh SEE ALSO | ||
| 100 | .Xr bsearch 3 , | ||
| 101 | .Xr hsearch 3 , | ||
| 102 | .Xr lsearch 3 | ||
| 103 | .Sh RETURN VALUES | ||
| 104 | The | ||
| 105 | .Fn tsearch | ||
| 106 | function returns NULL if allocation of a new node fails (usually | ||
| 107 | due to a lack of free memory). | ||
| 108 | .Pp | ||
| 109 | .Fn Tfind , | ||
| 110 | .Fn tsearch , | ||
| 111 | and | ||
| 112 | .Fn tdelete | ||
| 113 | return NULL if | ||
| 114 | .Fa rootp | ||
| 115 | is NULL or the datum cannot be found. | ||
| 116 | .Pp | ||
| 117 | The | ||
| 118 | .Fn twalk | ||
| 119 | function returns no value. | ||
