4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984 AT&T */
23 /* All Rights Reserved */
25 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */
29 * Tree search algorithm, generalized from Knuth (6.2.2) Algorithm T.
31 * The NODE * arguments are declared in the lint files as char *,
32 * because the definition of NODE isn't available to the user.
36 typedef char *POINTER
;
37 typedef struct node
{ POINTER key
; struct node
*llink
, *rlink
; } NODE
;
42 /* tfind - find a node, or return 0 */
44 tfind(key
, rootp
, compar
)
45 POINTER key
; /* Key to be located */
46 register NODE
**rootp
; /* Address of the root of the tree */
47 int (*compar
)(); /* Comparison function */
51 while (*rootp
!= NULL
) { /* T1: */
52 int r
= (*compar
)(key
, (*rootp
)->key
); /* T2: */
54 return (*rootp
); /* Key found */
56 &(*rootp
)->llink
: /* T3: Take left branch */
57 &(*rootp
)->rlink
; /* T4: Take right branch */
59 return (NODE
*)(NULL
);