avl_nearestfind the nearest node in an AVL tree

AVL Tree Library (libavl, -lavl)
#include <sys/avl.h>

void *
avl_nearest(avl_tree_t *tree, avl_index_t where, int direction);

The avl_nearest function returns the closest node in tree before or after the insertion point specified by where.

The value of where is obtained when a non-NULL pointer is passed in to the where argument of avl_find(3AVL) and it fails to find an entry in the tree.

If direction is set to AVL_AFTER, then the node that would logically have followed it will be returned. If direction is instead set to AVL_BEFORE, then the node that would have logically preceded it is returned.

When there is no nearest node, for example, AVL_AFTER is specified and the entry would have been the last node in the tree, then NULL is returned.

If the tree is modified between a call to avl_find(3AVL) and (), then the value of where from avl_find(3AVL) will no longer be valid and avl_find(3AVL) must be called again.

The avl_nearest() function returns the node that is closest or NULL if there is not a matching one.

See the EXAMPLES section in libavl(3LIB).

See Locking in libavl(3LIB).


May 7, 2015 OmniOS