Tree-M

 view release on metacpan or  search on metacpan

MT/MTnode.cpp  view on Meta::CPAN

/*********************************************************************
*                                                                    *
* Copyright (c) 1997,1998, 1999                                      *
* Multimedia DB Group and DEIS - CSITE-CNR,                          *
* University of Bologna, Bologna, ITALY.                             *
*                                                                    *
* All Rights Reserved.                                               *
*                                                                    *
* Permission to use, copy, and distribute this software and its      *
* documentation for NON-COMMERCIAL purposes and without fee is       *
* hereby granted provided  that this copyright notice appears in     *
* all copies.                                                        *
*                                                                    *
* THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE        *
* SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING  *
* BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,      *
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR  *
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A      *
* RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS    *
* DERIVATIVES.                                                       *
*                                                                    *
*********************************************************************/

#include <string.h>
#include "MT.h"
#include "MTpredicate.h"

double MIN_UTIL = 0.35;	// minimum node utilization
pp_function PROMOTE_PART_FUNCTION = CONFIRMED;	// promotion method
pv_function PROMOTE_VOTE_FUNCTION = mM_RAD;	// confirmed promotion method (if needed)
pp_function SECONDARY_PART_FUNCTION = RANDOM;	// root promotion method (can't use stored distances): used only for confirmed and MAX_UB_DIST methods
r_function RADIUS_FUNCTION = LB;	// mM_RAD promotion method (if needed)
int NUM_CANDIDATES = 10;	// number of candidates for sampling
s_function SPLIT_FUNCTION = BAL_G_HYPERPL;	// split method

extern int IOread;

// used to quick-sort the entries in a node according to their distance from the parent
int
MTentrycmp(const void *x, const void *y)
{
	double d=(*(MTentry **)x)->Key()->distance-(*(MTentry **)y)->Key()->distance;
	int i=0;

	if(d>0) i=1;
	else if(d<0) i=-1;
	return i;
}

// used in Split to find the next nearest entry
int
FindMin(double *vec, int veclen)
{
	int i, min_i=-1;
	double min=MAXDOUBLE;

	for(i=0; i<veclen; i++)
		if(vec[i]<min) {
			min_i=i;
			min=vec[i];
		}
	return min_i;
}

GiSTobject *
MTnode::NCopy()
{
	MTnode *newnode=(MTnode *)Copy();

	if((obj==NULL)&&(Path().Level()>1)) {
		MTentry *e=Entry();

		obj=newnode->obj=&(e->object());
		delete e;
	}
	newnode->InvalidateEntries();
	return newnode;
}

#ifdef PRINTING_OBJECTS
void
MTnode::Print(ostream& os) const
{
	if(obj!=NULL) os << *obj << " ";
//	else cout << "obj NULL...\n";
	os << ((MTnode *)this)->Path() << " #Entries: " << NumEntries() << ", Level " << Level();
	if(IsLeaf()) os << "(Leaf)";
	else os << "(Internal)";
	os << ", Sibling: " << Sibling() << ", Size: " << Size() << "/" << Tree()->Store()->PageSize() << endl;
	for(int i=0; i<NumEntries(); i++) (*this)[i]->Print(os);
}
#endif

int



( run in 0.575 second using v1.01-cache-2.11-cpan-5511b514fd6 )