コード例 #1
0
ファイル: heap.cpp プロジェクト: amarcott11/CS225
void heap<T, Compare>::heapifyUp( size_t currentIdx ) {
    if( currentIdx == root() )
        return;
    size_t parentIdx = parent( currentIdx );
    if( higherPriority( _elems[ currentIdx ], _elems[ parentIdx ] ) ) {
        std::swap( _elems[ currentIdx ], _elems[ parentIdx ] );
        heapifyUp( parentIdx );
    }
}
コード例 #2
0
ファイル: heap.cpp プロジェクト: amarcott11/CS225
void heap<T, Compare>::heapifyDown( size_t currentIdx ) {
    /// @todo Implement the heapifyDown algorithm.
	 if(!hasAChild(currentIdx))
        return;
    size_t pirorChildIdx =maxPriorityChild(currentIdx );
    if( !higherPriority( _elems[ currentIdx ], _elems[ pirorChildIdx ] ) ) {
        std::swap( _elems[ currentIdx ], _elems[ pirorChildIdx ] );
        heapifyDown(pirorChildIdx);
    }
}
コード例 #3
0
ファイル: heap.cpp プロジェクト: amarcott11/CS225
size_t heap<T, Compare>::maxPriorityChild( size_t currentIdx ) const {
    /// @todo Update to return the index of the child with highest priority
    ///   as defined by higherPriority()
	if(hasAChild(currentIdx))
	{
		if(higherPriority(_elems[leftChild(currentIdx)],_elems[rightChild(currentIdx)]))
			return leftChild(currentIdx);
		else
			return rightChild(currentIdx);
	}
    return 0;
}
コード例 #4
0
ファイル: heap.cpp プロジェクト: karanghai/cs225Labs
void heap<T, Compare>::heapifyDown( size_t currentIdx ) {
    /// @todo Implement the heapifyDown algorithm.
	if(hasAChild(currentIdx))
	{
	size_t minChildIndex=maxPriorityChild(currentIdx);
		if(!higherPriority(_elems[currentIdx],_elems[minChildIndex]))
		{
			std::swap(_elems[currentIdx],_elems[minChildIndex]);
			heapifyDown(minChildIndex);
		}
	}
}
コード例 #5
0
ファイル: heap.cpp プロジェクト: karanghai/cs225Labs
size_t heap<T, Compare>::maxPriorityChild( size_t currentIdx ) const {
    /// @todo Update to return the index of the child with highest priority
    ///   as defined by higherPriority()
	if(2*currentIdx+1>=_elems.size()) 
	return 2*currentIdx;	
	
	if(higherPriority(_elems[2*currentIdx],_elems[2*currentIdx+1]))   
	return 2*currentIdx; 

	else 
	return 2*currentIdx+1;
}
コード例 #6
0
void processEvents() {
    Event* event = NULL;
    Time processTime;
    Time platformTime;
    getRealTime(&platformTime);
    set_imask(15);
    event = peekEvent(NULL);
    while (event && higherPriority(event)) {
        safeToProcess(event, &processTime);
        if (compareTime(platformTime, processTime) >= 0) {
            queuePriority(event);
            removeAndPropagateSameTagEvents(event);
            setCurrentModelTag(event);
            set_imask(0);
            fireActor(event);
            getRealTime(&platformTime);
            set_imask(15);
            freeEvent(event);
            stackedDeadlineIndex--;
            event = NULL;
        }
        else {
            if (compareTime(processTime, lastTimerInterruptTime) == LESS) {
                lastTimerInterruptTime.secs = processTime.secs;
                lastTimerInterruptTime.nsecs = processTime.nsecs;
                setTimedInterrupt(&processTime);
            }
        }
        event = peekEvent(event);
    }
    /*
    if (stackedModelTagIndex >= 0) {
        currentMicrostep = executingModelTag[stackedModelTagIndex].microstep;
        currentModelTime = executingModelTag[stackedModelTagIndex].timestamp;
        stackedModelTagIndex--;
    } else {
        DBG(("cannot restore model tag\r\n"));
    }
    */
    set_imask(0);
}