fixed the under development line
[unix-history] / usr / src / usr.bin / gprof / lookup.c
CommitLineData
c0bc4ef7 1/*
7e9de516
KB
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
ddb85eed 4 *
6ecf3d85 5 * %sccs.include.redist.c%
c0bc4ef7
DF
6 */
7
6b32aa07 8#ifndef lint
7e9de516 9static char sccsid[] = "@(#)lookup.c 8.1 (Berkeley) %G%";
ddb85eed 10#endif /* not lint */
6b32aa07 11
31f0a970 12#include "gprof.h"
6b32aa07
PK
13
14 /*
15 * look up an address in a sorted-by-address namelist
16 * this deals with misses by mapping them to the next lower
17 * entry point.
18 */
19nltype *
20nllookup( address )
21 unsigned long address;
22{
23 register long low;
24 register long middle;
25 register long high;
26# ifdef DEBUG
27 register int probes;
28
29 probes = 0;
30# endif DEBUG
31 for ( low = 0 , high = nname - 1 ; low != high ; ) {
32# ifdef DEBUG
33 probes += 1;
34# endif DEBUG
35 middle = ( high + low ) >> 1;
36 if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) {
37# ifdef DEBUG
29da1d26 38 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
39 printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 );
40 }
41# endif DEBUG
42 return &nl[ middle ];
43 }
44 if ( nl[ middle ].value > address ) {
45 high = middle;
46 } else {
47 low = middle + 1;
48 }
49 }
86fc2026
KM
50# ifdef DEBUG
51 if ( debug & LOOKUPDEBUG ) {
52 fprintf( stderr , "[nllookup] (%d) binary search fails\n" ,
53 nname-1 );
54 }
55# endif DEBUG
6b32aa07
PK
56 return 0;
57}
58
59arctype *
60arclookup( parentp , childp )
61 nltype *parentp;
62 nltype *childp;
63{
64 arctype *arcp;
65
66 if ( parentp == 0 || childp == 0 ) {
3d5e7f25 67 fprintf( stderr, "[arclookup] parentp == 0 || childp == 0\n" );
6b32aa07
PK
68 return 0;
69 }
70# ifdef DEBUG
29da1d26 71 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
72 printf( "[arclookup] parent %s child %s\n" ,
73 parentp -> name , childp -> name );
74 }
75# endif DEBUG
76 for ( arcp = parentp -> children ; arcp ; arcp = arcp -> arc_childlist ) {
77# ifdef DEBUG
29da1d26 78 if ( debug & LOOKUPDEBUG ) {
6b32aa07
PK
79 printf( "[arclookup]\t arc_parent %s arc_child %s\n" ,
80 arcp -> arc_parentp -> name ,
81 arcp -> arc_childp -> name );
82 }
83# endif DEBUG
84 if ( arcp -> arc_childp == childp ) {
85 return arcp;
86 }
87 }
88 return 0;
89}