tsearch.3 (104400) | tsearch.3 (108037) |
---|---|
1.\" $NetBSD$ 2.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.\" OpenBSD: tsearch.3,v 1.2 1998/06/21 22:13:49 millert Exp | 1.\" $NetBSD$ 2.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.\" OpenBSD: tsearch.3,v 1.2 1998/06/21 22:13:49 millert Exp |
28.\" $FreeBSD: head/lib/libc/stdlib/tsearch.3 104400 2002-10-03 06:33:33Z mike $ | 28.\" $FreeBSD: head/lib/libc/stdlib/tsearch.3 108037 2002-12-18 12:45:11Z ru $ |
29.\" 30.Dd June 15, 1997 31.Dt TSEARCH 3 32.Os 33.Sh NAME 34.Nm tsearch , tfind , tdelete , twalk 35.Nd manipulate binary search trees 36.Sh SYNOPSIS --- 13 unchanged lines hidden (view full) --- 50.Fn tsearch , 51and 52.Fn twalk 53functions manage binary search trees based on algorithms T and D 54from Knuth (6.2.2). The comparison function passed in by 55the user has the same style of return values as 56.Xr strcmp 3 . 57.Pp | 29.\" 30.Dd June 15, 1997 31.Dt TSEARCH 3 32.Os 33.Sh NAME 34.Nm tsearch , tfind , tdelete , twalk 35.Nd manipulate binary search trees 36.Sh SYNOPSIS --- 13 unchanged lines hidden (view full) --- 50.Fn tsearch , 51and 52.Fn twalk 53functions manage binary search trees based on algorithms T and D 54from Knuth (6.2.2). The comparison function passed in by 55the user has the same style of return values as 56.Xr strcmp 3 . 57.Pp |
58.Fn Tfind | 58The 59.Fn tfind 60function |
59searches for the datum matched by the argument 60.Fa key 61in the binary tree rooted at 62.Fa rootp , 63returning a pointer to the datum if it is found and NULL 64if it is not. 65.Pp | 61searches for the datum matched by the argument 62.Fa key 63in the binary tree rooted at 64.Fa rootp , 65returning a pointer to the datum if it is found and NULL 66if it is not. 67.Pp |
66.Fn Tsearch | 68The 69.Fn tsearch 70function |
67is identical to 68.Fn tfind 69except that if no match is found, 70.Fa key 71is inserted into the tree and a pointer to it is returned. If 72.Fa rootp 73points to a NULL value a new binary search tree is created. 74.Pp | 71is identical to 72.Fn tfind 73except that if no match is found, 74.Fa key 75is inserted into the tree and a pointer to it is returned. If 76.Fa rootp 77points to a NULL value a new binary search tree is created. 78.Pp |
75.Fn Tdelete | 79The 80.Fn tdelete 81function |
76deletes a node from the specified binary search tree and returns 77a pointer to the parent of the node to be deleted. 78It takes the same arguments as 79.Fn tfind 80and 81.Fn tsearch . 82If the node to be deleted is the root of the binary search tree, 83.Fa rootp 84will be adjusted. 85.Pp | 82deletes a node from the specified binary search tree and returns 83a pointer to the parent of the node to be deleted. 84It takes the same arguments as 85.Fn tfind 86and 87.Fn tsearch . 88If the node to be deleted is the root of the binary search tree, 89.Fa rootp 90will be adjusted. 91.Pp |
86.Fn Twalk | 92The 93.Fn twalk 94function |
87walks the binary search tree rooted in 88.Fa root 89and calls the function 90.Fa action 91on each node. 92.Fa Action 93is called with three arguments: a pointer to the current node, 94a value from the enum --- 5 unchanged lines hidden (view full) --- 100.Xr hsearch 3 , 101.Xr lsearch 3 102.Sh RETURN VALUES 103The 104.Fn tsearch 105function returns NULL if allocation of a new node fails (usually 106due to a lack of free memory). 107.Pp | 95walks the binary search tree rooted in 96.Fa root 97and calls the function 98.Fa action 99on each node. 100.Fa Action 101is called with three arguments: a pointer to the current node, 102a value from the enum --- 5 unchanged lines hidden (view full) --- 108.Xr hsearch 3 , 109.Xr lsearch 3 110.Sh RETURN VALUES 111The 112.Fn tsearch 113function returns NULL if allocation of a new node fails (usually 114due to a lack of free memory). 115.Pp |
108.Fn Tfind , | 116The 117.Fn tfind , |
109.Fn tsearch , 110and 111.Fn tdelete | 118.Fn tsearch , 119and 120.Fn tdelete |
121functions |
|
112return NULL if 113.Fa rootp 114is NULL or the datum cannot be found. 115.Pp 116The 117.Fn twalk 118function returns no value. | 122return NULL if 123.Fa rootp 124is NULL or the datum cannot be found. 125.Pp 126The 127.Fn twalk 128function returns no value. |