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 ); } }
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); } }
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; }
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); } } }
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; }
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); }