| 1 | #ifndef lint |
| 2 | static char *sccsid = "@(#)lookup.c 1.3 (Berkeley) %G%"; |
| 3 | #endif lint |
| 4 | |
| 5 | #include "gprof.h" |
| 6 | |
| 7 | /* |
| 8 | * look up an address in a sorted-by-address namelist |
| 9 | * this deals with misses by mapping them to the next lower |
| 10 | * entry point. |
| 11 | */ |
| 12 | nltype * |
| 13 | nllookup( address ) |
| 14 | unsigned long address; |
| 15 | { |
| 16 | register long low; |
| 17 | register long middle; |
| 18 | register long high; |
| 19 | # ifdef DEBUG |
| 20 | register int probes; |
| 21 | |
| 22 | probes = 0; |
| 23 | # endif DEBUG |
| 24 | for ( low = 0 , high = nname - 1 ; low != high ; ) { |
| 25 | # ifdef DEBUG |
| 26 | probes += 1; |
| 27 | # endif DEBUG |
| 28 | middle = ( high + low ) >> 1; |
| 29 | if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) { |
| 30 | # ifdef DEBUG |
| 31 | if ( debug & LOOKUPDEBUG ) { |
| 32 | printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 ); |
| 33 | } |
| 34 | # endif DEBUG |
| 35 | return &nl[ middle ]; |
| 36 | } |
| 37 | if ( nl[ middle ].value > address ) { |
| 38 | high = middle; |
| 39 | } else { |
| 40 | low = middle + 1; |
| 41 | } |
| 42 | } |
| 43 | fprintf( stderr , "[nllookup] binary search fails???\n" ); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | arctype * |
| 48 | arclookup( parentp , childp ) |
| 49 | nltype *parentp; |
| 50 | nltype *childp; |
| 51 | { |
| 52 | arctype *arcp; |
| 53 | |
| 54 | if ( parentp == 0 || childp == 0 ) { |
| 55 | fprintf( "[arclookup] parentp == 0 || childp == 0\n" ); |
| 56 | return 0; |
| 57 | } |
| 58 | # ifdef DEBUG |
| 59 | if ( debug & LOOKUPDEBUG ) { |
| 60 | printf( "[arclookup] parent %s child %s\n" , |
| 61 | parentp -> name , childp -> name ); |
| 62 | } |
| 63 | # endif DEBUG |
| 64 | for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) { |
| 65 | # ifdef DEBUG |
| 66 | if ( debug & LOOKUPDEBUG ) { |
| 67 | printf( "[arclookup]\t arc_parent %s arc_child %s\n" , |
| 68 | arcp -> arc_parentp -> name , |
| 69 | arcp -> arc_childp -> name ); |
| 70 | } |
| 71 | # endif DEBUG |
| 72 | if ( arcp -> arc_childp == childp ) { |
| 73 | return arcp; |
| 74 | } |
| 75 | } |
| 76 | return 0; |
| 77 | } |