src/addrserial/addrtracker.cpp
// functions for rapid prototype of random-ness----------------
functions for rapid prototype of random-ness
functions for rapid prototype of random - ness
thrID AddrTracker::chooseRandomThread(map<thrID, bool>::iterator begin,
        map<thrID, bool>::iterator end) {
    map<thrID, bool>::iterator itr;
    int numberOfChoices= 0;
    for (itr = begin; itr != end; itr++) {
        if (itr->second) {
            numberOfChoices++;
        }
    }
    if (numberOfChoices == 0) {
        return -1;
    }
    int chosenThread = 0;
    if (numberOfChoices > 1) {
        chosenThread = log->getRandomNumber() % numberOfChoices;
    }
    for (itr = begin; itr != end; itr++) {
        if (itr->second) {
            chosenThread--;
            if (chosenThread < 0) {
                return itr->first;
            }
        }
    }
    printf("NOC: %d, chosenThread: %d\n", numberOfChoices, chosenThread);
    safe_assert(false);
    return -1;
}
thrID AddrTracker :: chooseRandomThread ( map < thrID , bool > :: iterator begin , map < thrID , bool > :: iterator end ) { map < thrID , bool > :: iterator itr ; int numberOfChoices = 0 ; for ( itr = begin ; itr != end ; itr ++ ) { if ( itr -> second ) { numberOfChoices ++ ; } } if ( numberOfChoices == 0 ) { return -1 ; } int chosenThread = 0 ; if ( numberOfChoices > 1 ) { chosenThread = log -> getRandomNumber ( ) % numberOfChoices ; } for ( itr = begin ; itr != end ; itr ++ ) { if ( itr -> second ) { chosenThread -- ; if ( chosenThread < 0 ) { return itr -> first ; } } } printf ( " \n " , numberOfChoices , chosenThread ) ; safe_assert ( false ) ; return -1 ; }
functions for rapid prototype of random-ness
functions for rapid prototype of random - ness