/**************************************************************************
 * Source Id :
 *
 * $Id: dbbst.cpp,v 1.3 2001/04/20 10:15:01 georgetasker Exp $
 *-------------------------------------------------------------------------
 * Project Notes :
 *
 *  Diamond Base
 *  ============
 *      A solid database implementation, spurred on by the continuing
 *  Metal (Lead) Base saga.
 *
 *  Project Team :
 *        A. Davison
 *        K. Lentin
 *        D. Platt
 *
 *	Project Commenced : 05-02-1993
 *
 *-------------------------------------------------------------------------
 *  Module Notes :
 *
 *  Binary search tree for the nameserver.
 *
 *
 *  Original Author : Andy
 *
 **************************************************************************/

// FOR NOW::
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#include <diamond/dbbst.h>

bool
DBBSTNode::insert(DBBSTNode* const node)
{
	int side = compare(node, this);
	bool res = true;
	if (side < 0) {
		if (_left == 0)
			_left = node;
		else
			res = _left->insert(node);
	} else if (side > 0) {
		if (_right ==0)
			_right = node;
		else
			res = _right->insert(node);
	} else {
		// The element is already in there. Delete it and return an error.
		// Kev 29/11/94 Actually, let's be nice and not nuke someone else's
		// data
		//delete node;
		res = false;
	}
	return res;
}

DBBSTNode* DBBSTNode::lookup(const DBBSTNode* node)
{
	int side = compare(node,this);
	if (side == 0)
		return this;
	else if (side < 0)
	{
		if (_left == 0)
			return 0;
		else
			return _left->lookup(node);
	}
	else
	{
		if (_right == 0)
			return 0;
		else
			return _right->lookup(node);
	}
}

void DBBSTNode::inorder()
{
	if (_left != 0)
		_left->inorder();
	show();
	if(_right != 0)
		_right->inorder();
}

///////////////////////////////////////////////////////////////////////////
// Revision History:
//
// $Log: dbbst.cpp,v $
// Revision 1.3  2001/04/20 10:15:01  georgetasker
// Cygwin compilation fixes, compilation speed enhancements
// Code modified to get rid of some compiler warnings
//
// Revision 1.2  2001/04/19 21:12:54  georgetasker
// cygwin compilation fixes
//
// Revision 1.1  2001/04/04 12:05:49  aleksandras
// forgotten diamond .cpps
//
// Revision 1.4  1995/06/27  13:27:16  kevinl
// Fixes to repair the gcc 2.7.0 carnage:
// modified for loop local variable scope semantics
// some new errors invented.
// moved some inline friends out of classes (stoopid - mystring)
// Modified the setUnique generated member
//
// Revision 1.3  1994/12/12  03:54:14  kevinl
// Fixed problems with return code of tree insertion
//
// Revision 1.2  1994/02/03  05:54:19  kevinl
// Moved include files to diamond/ and fixed HAVE_MALLOC_H
//
///////////////////////////////////////////////////////////////////////////
