2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Binary tree access. The routines contained in this file are: 2N/A * These have the same interfaces as tsearch(3C), tfind(3C), and 2N/A * twalk(3C), with two important distinctions: 2N/A * - libc twalk is inadequate, since it doesn't allow the caller to pass 2N/A * cookies into the action function (prohibiting thread-safe usage). 2N/A * slp_twalk allows cookies. 2N/A * - libc tsearch and tfind *always* lock access to the tree. This can 2N/A * be inefficient when it isn't necessary to lock the tree in order 2N/A * to ensure thread-safety. It is the responsibility of the caller to 2N/A * ensure that slp_tsearch and slp_tfind are safe for concurrent access. 2N/A * It is possible for this implementation to degenerate into a 2N/A * linked-list algorithm with certain inputs. If this proves to be 2N/A * a problem in practice, these routines can be optimized by balancing 2N/A/* Find or insert key into search tree */ 2N/A NODE *q;
/* New node if key not found */ 2N/A return ((
void *)*
rootp);
/* Key found */ 2N/A if (q !=
NULL) {
/* Allocate new node */ 2N/A return ((
void *)*
rootp);
/* Key found */