1fa9922c2SRobert Mustacchi.\" 2fa9922c2SRobert Mustacchi.\" This file and its contents are supplied under the terms of the 3fa9922c2SRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0. 4fa9922c2SRobert Mustacchi.\" You may only use this file in accordance with the terms of version 5fa9922c2SRobert Mustacchi.\" 1.0 of the CDDL. 6fa9922c2SRobert Mustacchi.\" 7fa9922c2SRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this 8fa9922c2SRobert Mustacchi.\" source. A copy of the CDDL is also available via the Internet at 9fa9922c2SRobert Mustacchi.\" http://www.illumos.org/license/CDDL. 10fa9922c2SRobert Mustacchi.\" 11fa9922c2SRobert Mustacchi.\" 12fa9922c2SRobert Mustacchi.\" Copyright 2015 Joyent, Inc. 13fa9922c2SRobert Mustacchi.\" 14fa9922c2SRobert Mustacchi.Dd May 07, 2015 15fa9922c2SRobert Mustacchi.Dt AVL_FIND 3AVL 16fa9922c2SRobert Mustacchi.Os 17fa9922c2SRobert Mustacchi.Sh NAME 18fa9922c2SRobert Mustacchi.Nm avl_find 19fa9922c2SRobert Mustacchi.Nd find a node in an AVL tree 20fa9922c2SRobert Mustacchi.Sh SYNOPSIS 21fa9922c2SRobert Mustacchi.Lb libavl 22fa9922c2SRobert Mustacchi.In sys/avl.h 23fa9922c2SRobert Mustacchi.Ft void * 24fa9922c2SRobert Mustacchi.Fo avl_find 25fa9922c2SRobert Mustacchi.Fa "avl_tree_t *tree" 26fa9922c2SRobert Mustacchi.Fa "const void *node" 27fa9922c2SRobert Mustacchi.Fa "avl_index_t *where" 28fa9922c2SRobert Mustacchi.Fc 29fa9922c2SRobert Mustacchi.Sh DESCRIPTION 30fa9922c2SRobert MustacchiThe 31fa9922c2SRobert Mustacchi.Fn avl_find 32fa9922c2SRobert Mustacchifunction is used to look up a node in the tree rooted at 33fa9922c2SRobert Mustacchi.Fa tree . 34fa9922c2SRobert Mustacchi.Pp 35fa9922c2SRobert MustacchiTo perform a lookup, a caller should construct an instance of the data 36fa9922c2SRobert Mustacchistructure, the argument 37fa9922c2SRobert Mustacchi.Fa node . 38fa9922c2SRobert Mustacchi.Fn avl_find 39fa9922c2SRobert Mustacchisearches through the tree for a node which compares equal to the passed 40fa9922c2SRobert Mustacchiin 41fa9922c2SRobert Mustacchi.Fa node 42fa9922c2SRobert Mustacchiusing the comparison function specified when the tree was created with 43fa9922c2SRobert Mustacchi.Xr avl_create 3AVL . 44fa9922c2SRobert MustacchiThe only fields of 45fa9922c2SRobert Mustacchi.Fa node 46fa9922c2SRobert Mustacchithat need to be initialized are those that the comparison function will 47fa9922c2SRobert Mustacchiuse, the others may remain uninitialized. 48fa9922c2SRobert Mustacchi.Pp 49fa9922c2SRobert MustacchiIf a match exists in the tree, then that entry will be returned. 50fa9922c2SRobert MustacchiOtherwise, 51fa9922c2SRobert Mustacchi.Sy NULL 52fa9922c2SRobert Mustacchiis returned. 53fa9922c2SRobert Mustacchi.Pp 54fa9922c2SRobert MustacchiIf 55fa9922c2SRobert Mustacchi.Fa node 56fa9922c2SRobert Mustacchidoes not match anything in the tree and the value of 57fa9922c2SRobert Mustacchi.Fa where 58fa9922c2SRobert Mustacchiis a 59fa9922c2SRobert Mustacchi.Pf non- Sy NULL 60fa9922c2SRobert Mustacchipointer, then 61fa9922c2SRobert Mustacchi.Fa where 62fa9922c2SRobert Mustacchiwill be updated to a value that can be used with both 63fa9922c2SRobert Mustacchi.Xr avl_insert 3AVL 64fa9922c2SRobert Mustacchiand 65fa9922c2SRobert Mustacchi.Xr avl_nearest 3AVL . 66fa9922c2SRobert MustacchiThis value is only valid as long as the tree is not modified. If 67fa9922c2SRobert Mustacchianything is added or removed from the tree, then the value of 68fa9922c2SRobert Mustacchi.Fa where 69fa9922c2SRobert Mustacchiis no longer valid. This is commonly used as part of a pattern to see if 70fa9922c2SRobert Mustacchisomething that should be added to the tree already exists, and if not, 71fa9922c2SRobert Mustacchiinsert it. For more information, see the examples in 72fa9922c2SRobert Mustacchi.Xr libavl 3LIB . 73fa9922c2SRobert Mustacchi.Pp 74fa9922c2SRobert MustacchiIf the lookup is successful, then the contents of 75fa9922c2SRobert Mustacchi.Fa where 76fa9922c2SRobert Mustacchiare undefined. 77fa9922c2SRobert Mustacchi.Sh RETURN VALUES 78fa9922c2SRobert MustacchiIf 79fa9922c2SRobert Mustacchi.Fa node 80fa9922c2SRobert Mustacchimatches an entry in the tree, the matching entry is returned. Otherwise, 81fa9922c2SRobert Mustacchi.Sy NULL 82fa9922c2SRobert Mustacchiis returned and if 83fa9922c2SRobert Mustacchi.Fa where 84fa9922c2SRobert Mustacchiis 85fa9922c2SRobert Mustacchi.Pf non- Sy NULL , 86fa9922c2SRobert Mustacchiit is updated to point to a location in the tree. 87fa9922c2SRobert Mustacchi.Sh EXAMPLES 88fa9922c2SRobert MustacchiSee the 89fa9922c2SRobert Mustacchi.Sy EXAMPLES 90fa9922c2SRobert Mustacchisection in 91fa9922c2SRobert Mustacchi.Xr libavl 3LIB . 92fa9922c2SRobert Mustacchi.Sh INTERFACE STABILITY 93fa9922c2SRobert Mustacchi.Sy Committed 94fa9922c2SRobert Mustacchi.Sh MT-Level 95fa9922c2SRobert MustacchiSee 96fa9922c2SRobert Mustacchi.Sx Locking 97fa9922c2SRobert Mustacchiin 98fa9922c2SRobert Mustacchi.Xr libavl 3LIB . 99fa9922c2SRobert Mustacchi.Sh SEE ALSO 100fa9922c2SRobert Mustacchi.Xr avl_create 3AVL , 101fa9922c2SRobert Mustacchi.Xr avl_insert 3AVL , 102*3a005aadSYuri Pankov.Xr avl_nearest 3AVL , 103*3a005aadSYuri Pankov.Xr libavl 3LIB 104