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