//-----------------------------------------------------------------------------
// Copyright © 2003 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/avl
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// G. M. Adelson-Velskii and E. M. Landis are the inventors of the algorithm
// bearing their initials, AVL.  Their algorithm for height-balanced binary
// search trees is the basis of the code in this package.  Some modification
// is made to the balancing operations, and features are added for practical
// purposes.
//-----------------------------------------------------------------------------

#include "avl_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	avl_unselect
//
// purpose	Clear the selection of the current node so that there is
//		no node currently selected.  This causes, for example, the
//		avl_forward() function to get the first node the next time
//		it is called for this tree.
//
// arguments	1 (AVL *) pointer to root of the binary tree
//
// returns	(void *) pointer to the previously selected node
//		(void *) NULL if no node was previously selected
//-----------------------------------------------------------------------------
void *
avl_unselect (
    AVL *		arg_tree
    )
__PROTO_END__
{
    avl_link *		link_p		;


#if AVL_CHECK_ARGS
    //---------------------------------
    // Make sure we have a binary tree.
    //---------------------------------
    if ( ! arg_tree ) return NULL;
#endif

#if AVL_PARANOID_LOGIC
#if AVL_COUNT_ENABLE
    //------------------------------------------------------
    // Make sure there are supposed to be nodes in the tree.
    //------------------------------------------------------
    if ( avl_count_get_nodes( arg_tree ) < 1 ) return NULL;
#endif /* AVL_COUNT_ENABLE */
#endif /* AVL_PARANOID_LOGIC */

    //--------------------------------------------
    // Grab previous node and clear the selection.
    //--------------------------------------------
    link_p = arg_tree->select;
    arg_tree->select = NULL;

    //-- Return previously selected node.
    return ( link_p ) ? avl_link_to_node( arg_tree, link_p ) : NULL;
}

