date and time created 81/10/15 13:47:05 by peter
[unix-history] / usr / src / usr.bin / gprof / lookup.c
#ifndef lint
static char *sccsid = "@(#)lookup.c 1.1 (Berkeley) %G%";
#endif lint
#include "dprof.h"
/*
* look up an address in a sorted-by-address namelist
* this deals with misses by mapping them to the next lower
* entry point.
*/
nltype *
nllookup( address )
unsigned long address;
{
register long low;
register long middle;
register long high;
# ifdef DEBUG
register int probes;
probes = 0;
# endif DEBUG
for ( low = 0 , high = nname - 1 ; low != high ; ) {
# ifdef DEBUG
probes += 1;
# endif DEBUG
middle = ( high + low ) >> 1;
if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) {
# ifdef DEBUG
if ( debug & TALLYDEBUG ) {
printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
}
# endif DEBUG
return &nl[ middle ];
}
if ( nl[ middle ].value > address ) {
high = middle;
} else {
low = middle + 1;
}
}
fprintf( stderr , "[nllookup] binary search fails???\n" );
return 0;
}
arctype *
arclookup( parentp , childp )
nltype *parentp;
nltype *childp;
{
arctype *arcp;
if ( parentp == 0 || childp == 0 ) {
fprintf( "[arclookup] parentp == 0 || childp == 0\n" );
return 0;
}
# ifdef DEBUG
if ( debug & TALLYDEBUG ) {
printf( "[arclookup] parent %s child %s\n" ,
parentp -> name , childp -> name );
}
# endif DEBUG
for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
# ifdef DEBUG
if ( debug & TALLYDEBUG ) {
printf( "[arclookup]\t arc_parent %s arc_child %s\n" ,
arcp -> arc_parentp -> name ,
arcp -> arc_childp -> name );
}
# endif DEBUG
if ( arcp -> arc_childp == childp ) {
return arcp;
}
}
return 0;
}