xref: /titanic_51/usr/src/man/man3avl/avl_nearest.3avl (revision fa9922c2be34868be01989cef133828185b5c0bc)
1*fa9922c2SRobert Mustacchi.\"
2*fa9922c2SRobert Mustacchi.\" This file and its contents are supplied under the terms of the
3*fa9922c2SRobert Mustacchi.\" Common Development and Distribution License ("CDDL"), version 1.0.
4*fa9922c2SRobert Mustacchi.\" You may only use this file in accordance with the terms of version
5*fa9922c2SRobert Mustacchi.\" 1.0 of the CDDL.
6*fa9922c2SRobert Mustacchi.\"
7*fa9922c2SRobert Mustacchi.\" A full copy of the text of the CDDL should have accompanied this
8*fa9922c2SRobert Mustacchi.\" source.  A copy of the CDDL is also available via the Internet at
9*fa9922c2SRobert Mustacchi.\" http://www.illumos.org/license/CDDL.
10*fa9922c2SRobert Mustacchi.\"
11*fa9922c2SRobert Mustacchi.\"
12*fa9922c2SRobert Mustacchi.\" Copyright 2015 Joyent, Inc.
13*fa9922c2SRobert Mustacchi.\"
14*fa9922c2SRobert Mustacchi.Dd May 07, 2015
15*fa9922c2SRobert Mustacchi.Dt AVL_NEAREST 3AVL
16*fa9922c2SRobert Mustacchi.Os
17*fa9922c2SRobert Mustacchi.Sh NAME
18*fa9922c2SRobert Mustacchi.Nm avl_nearest
19*fa9922c2SRobert Mustacchi.Nd find the nearest node in an AVL tree
20*fa9922c2SRobert Mustacchi.Sh SYNOPSIS
21*fa9922c2SRobert Mustacchi.Lb libavl
22*fa9922c2SRobert Mustacchi.In sys/avl.h
23*fa9922c2SRobert Mustacchi.Ft void *
24*fa9922c2SRobert Mustacchi.Fo avl_nearest
25*fa9922c2SRobert Mustacchi.Fa "avl_tree_t *tree"
26*fa9922c2SRobert Mustacchi.Fa "avl_index_t where"
27*fa9922c2SRobert Mustacchi.Fa "int direction"
28*fa9922c2SRobert Mustacchi.Fc
29*fa9922c2SRobert Mustacchi.Sh DESCRIPTION
30*fa9922c2SRobert MustacchiThe
31*fa9922c2SRobert Mustacchi.Fa avl_nearest
32*fa9922c2SRobert Mustacchifunction returns the closest node in
33*fa9922c2SRobert Mustacchi.Fa tree
34*fa9922c2SRobert Mustacchibefore or after the insertion point specified by
35*fa9922c2SRobert Mustacchi.Fa where .
36*fa9922c2SRobert Mustacchi.Pp
37*fa9922c2SRobert MustacchiThe value of
38*fa9922c2SRobert Mustacchi.Fa where
39*fa9922c2SRobert Mustacchiis obtained when a
40*fa9922c2SRobert Mustacchi.Pf non- Dv NULL
41*fa9922c2SRobert Mustacchipointer is passed in to the
42*fa9922c2SRobert Mustacchi.Fa where
43*fa9922c2SRobert Mustacchiargument of
44*fa9922c2SRobert Mustacchi.Xr avl_find 3AVL
45*fa9922c2SRobert Mustacchiand it fails to find an entry in the tree.
46*fa9922c2SRobert Mustacchi.Pp
47*fa9922c2SRobert MustacchiIf
48*fa9922c2SRobert Mustacchi.Fa direction
49*fa9922c2SRobert Mustacchiis set to
50*fa9922c2SRobert Mustacchi.Dv AVL_AFTER ,
51*fa9922c2SRobert Mustacchithen the node that would logically have followed it will be returned. If
52*fa9922c2SRobert Mustacchi.Fa direction
53*fa9922c2SRobert Mustacchiis instead set to
54*fa9922c2SRobert Mustacchi.Dv AVL_BEFORE ,
55*fa9922c2SRobert Mustacchithen the node that would have logically preceded it is returned.
56*fa9922c2SRobert Mustacchi.Pp
57*fa9922c2SRobert MustacchiWhen there is no nearest node, for example,
58*fa9922c2SRobert Mustacchi.Dv AVL_AFTER
59*fa9922c2SRobert Mustacchiis specified and the entry would have been the last node in the tree,
60*fa9922c2SRobert Mustacchithen
61*fa9922c2SRobert Mustacchi.Sy NULL is returned .
62*fa9922c2SRobert Mustacchi.Pp
63*fa9922c2SRobert MustacchiIf the tree is modified between a call to
64*fa9922c2SRobert Mustacchi.Xr avl_find 3AVL
65*fa9922c2SRobert Mustacchiand
66*fa9922c2SRobert Mustacchi.Fn avl_nearest ,
67*fa9922c2SRobert Mustacchithen the value of
68*fa9922c2SRobert Mustacchi.Fa where
69*fa9922c2SRobert Mustacchifrom
70*fa9922c2SRobert Mustacchi.Xr avl_find 3AVL
71*fa9922c2SRobert Mustacchiwill no longer be valid and
72*fa9922c2SRobert Mustacchi.Xr avl_find 3AVL
73*fa9922c2SRobert Mustacchimust be called again.
74*fa9922c2SRobert Mustacchi.Sh RETURN VALUES
75*fa9922c2SRobert MustacchiThe
76*fa9922c2SRobert Mustacchi.Fn avl_nearest
77*fa9922c2SRobert Mustacchifunction returns the node that is closest or
78*fa9922c2SRobert Mustacchi.Sy NULL
79*fa9922c2SRobert Mustacchiif there is not a matching one.
80*fa9922c2SRobert Mustacchi.Sh EXAMPLES
81*fa9922c2SRobert MustacchiSee the
82*fa9922c2SRobert Mustacchi.Sy EXAMPLES
83*fa9922c2SRobert Mustacchisection in
84*fa9922c2SRobert Mustacchi.Xr libavl 3LIB .
85*fa9922c2SRobert Mustacchi.Sh INTERFACE STABILITY
86*fa9922c2SRobert Mustacchi.Sy Committed
87*fa9922c2SRobert Mustacchi.Sh MT-Level
88*fa9922c2SRobert MustacchiSee
89*fa9922c2SRobert Mustacchi.Sx Locking
90*fa9922c2SRobert Mustacchiin
91*fa9922c2SRobert Mustacchi.Xr libavl 3LIB .
92*fa9922c2SRobert Mustacchi.Sh SEE ALSO
93*fa9922c2SRobert Mustacchi.Xr libavl 3LIB
94