Annotation of 43BSD/ucb/gprof/lookup.c, revision 1.1

1.1     ! root        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: 
        !             7: #ifndef lint
        !             8: static char sccsid[] = "@(#)lookup.c   5.1 (Berkeley) 6/4/85";
        !             9: #endif not lint
        !            10: 
        !            11: #include "gprof.h"
        !            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
        !            37:                if ( debug & LOOKUPDEBUG ) {
        !            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
        !            65:        if ( debug & LOOKUPDEBUG ) {
        !            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
        !            72:            if ( debug & LOOKUPDEBUG ) {
        !            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: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.