Commit | Line | Data |
---|---|---|
c0bc4ef7 DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
ddb85eed KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
c0bc4ef7 DF |
11 | */ |
12 | ||
6b32aa07 | 13 | #ifndef lint |
ddb85eed KB |
14 | static char sccsid[] = "@(#)lookup.c 5.2 (Berkeley) %G%"; |
15 | #endif /* not lint */ | |
6b32aa07 | 16 | |
31f0a970 | 17 | #include "gprof.h" |
6b32aa07 PK |
18 | |
19 | /* | |
20 | * look up an address in a sorted-by-address namelist | |
21 | * this deals with misses by mapping them to the next lower | |
22 | * entry point. | |
23 | */ | |
24 | nltype * | |
25 | nllookup( address ) | |
26 | unsigned long address; | |
27 | { | |
28 | register long low; | |
29 | register long middle; | |
30 | register long high; | |
31 | # ifdef DEBUG | |
32 | register int probes; | |
33 | ||
34 | probes = 0; | |
35 | # endif DEBUG | |
36 | for ( low = 0 , high = nname - 1 ; low != high ; ) { | |
37 | # ifdef DEBUG | |
38 | probes += 1; | |
39 | # endif DEBUG | |
40 | middle = ( high + low ) >> 1; | |
41 | if ( nl[ middle ].value <= address && nl[ middle+1 ].value > address ) { | |
42 | # ifdef DEBUG | |
29da1d26 | 43 | if ( debug & LOOKUPDEBUG ) { |
6b32aa07 PK |
44 | printf( "[nllookup] %d (%d) probes\n" , probes , nname-1 ); |
45 | } | |
46 | # endif DEBUG | |
47 | return &nl[ middle ]; | |
48 | } | |
49 | if ( nl[ middle ].value > address ) { | |
50 | high = middle; | |
51 | } else { | |
52 | low = middle + 1; | |
53 | } | |
54 | } | |
55 | fprintf( stderr , "[nllookup] binary search fails???\n" ); | |
56 | return 0; | |
57 | } | |
58 | ||
59 | arctype * | |
60 | arclookup( parentp , childp ) | |
61 | nltype *parentp; | |
62 | nltype *childp; | |
63 | { | |
64 | arctype *arcp; | |
65 | ||
66 | if ( parentp == 0 || childp == 0 ) { | |
67 | fprintf( "[arclookup] parentp == 0 || childp == 0\n" ); | |
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 | } |