//-----------------------------------------------------------------------------
// 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/map
// 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 112 columns wide.
//-----------------------------------------------------------------------------

#include "map_sla.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	map_sla_compare (internal)
//
// purpose	Compare the array keys in two AVL tree nodes.  This function
//		is not intended for direct reference by application programs.
//		It is used only to establish the comparison method for the
//		AVL tree used to hold this mapping.
//
// features	This function is the core fast comparison.
//
// arguments	1 (struct map_link_sla *)
//		2 (struct map_link_sla *)
//		3 (AVL *) AVL link pointer (ignored)
//
// returns	(int) comparison status, -1, 0, 1
//-----------------------------------------------------------------------------
int
map_sla_compare (
    avl_link *		arg_one
    ,
    avl_link *		arg_two
    ,
    AVL *		arg_avl
    )
__PROTO_END__
{
    signed long *		str1	;
    signed long *		str2	;
    size_t		rem1	;
    size_t		rem2	;

    str1 = (signed long *)( ( (struct map_link_sla *) (void *) arg_one )->key );
    rem1 = ( (struct map_link_sla *) (void *) arg_one )->keylen;

    str2 = (signed long *)( ( (struct map_link_sla *) (void *) arg_two )->key );
    rem2 = ( (struct map_link_sla *) (void *) arg_two )->keylen;

    //-----------------------------
    // Begin the main compare loop.
    //-----------------------------
    for (;;) {

        //-- If either string is exhausted then return now.
        if ( rem1 == 0 ) return ( rem2 == 0 ) ? 0 : -1;
        if ( rem2 == 0 ) return 1;

	//-- If unequal then return the difference.
	if ( * str1 != * str2 ) return ( * str1 < * str2 ) ? -1 : 1;

	//-- Next.
	++ str1;
	++ str2;
	-- rem1;
	-- rem2;
    }
    //-- Never get here.
}


