inline void TimerBase::checkHeapIndex() const { ASSERT(!timerHeap().isEmpty()); ASSERT(m_heapIndex >= 0); ASSERT(m_heapIndex < static_cast<int>(timerHeap().size())); ASSERT(timerHeap()[m_heapIndex] == this); }
inline void TimerBase::heapInsert() { ASSERT(!inHeap()); timerHeap().append(this); m_heapIndex = timerHeap().size() - 1; heapDecreaseKey(); }
void TimerBase::heapPopMin() { ASSERT(this == timerHeap().first()); checkHeapIndex(); pop_heap(TimerHeapIterator(0), TimerHeapIterator(timerHeap().size())); checkHeapIndex(); ASSERT(this == timerHeap().last()); }
void TimerBase::heapPopMin() { ASSERT(this == timerHeap().first()); checkHeapIndex(); Vector<TimerBase*>& heap = timerHeap(); TimerBase** heapData = heap.data(); pop_heap(TimerHeapIterator(heapData), TimerHeapIterator(heapData + heap.size()), TimerHeapLessThanFunction()); checkHeapIndex(); ASSERT(this == timerHeap().last()); }
void TimerBase::heapDeleteMin() { ASSERT(m_nextFireTime == 0); heapPopMin(); timerHeap().removeLast(); m_heapIndex = -1; }
inline TimerHeapReference& TimerHeapReference::operator=(TimerBase* timer) { m_reference = timer; Vector<TimerBase*>& heap = timerHeap(); if (&m_reference >= heap.data() && &m_reference < heap.data() + heap.size()) timer->m_heapIndex = &m_reference - heap.data(); return *this; }
void TimerBase::heapDecreaseKey() { ASSERT(m_nextFireTime != 0); checkHeapIndex(); TimerBase** heapData = timerHeap().data(); push_heap(TimerHeapIterator(heapData), TimerHeapIterator(heapData + m_heapIndex + 1), TimerHeapLessThanFunction()); checkHeapIndex(); }
inline TimerHeapElement& TimerHeapElement::operator=(const TimerHeapElement& o) { TimerBase* t = o.timer(); m_timer = t; if (m_index != -1) { checkConsistency(); timerHeap()[m_index] = t; t->m_heapIndex = m_index; } return *this; }
void checkConsistency(ptrdiff_t offset = 0) const { ASSERT(m_pointer >= timerHeap().data()); ASSERT(m_pointer <= timerHeap().data() + timerHeap().size()); ASSERT_UNUSED(offset, m_pointer + offset >= timerHeap().data()); ASSERT_UNUSED(offset, m_pointer + offset <= timerHeap().data() + timerHeap().size()); }
bool TimerBase::hasValidHeapPosition() const { ASSERT(m_nextFireTime); if (!inHeap()) return false; // Check if the heap property still holds with the new fire time. If it does we don't need to do anything. // This assumes that the STL heap is a standard binary heap. In an unlikely event it is not, the assertions // in updateHeapIfNeeded() will get hit. const Vector<TimerBase*>& heap = timerHeap(); if (!parentHeapPropertyHolds(this, heap, m_heapIndex)) return false; unsigned childIndex1 = 2 * m_heapIndex + 1; unsigned childIndex2 = childIndex1 + 1; return childHeapPropertyHolds(this, heap, childIndex1) && childHeapPropertyHolds(this, heap, childIndex2); }
void checkConsistency() const { ASSERT(m_index >= 0); ASSERT(m_index < static_cast<int>(timerHeap().size())); }
explicit TimerHeapElement(int i) : m_index(i) , m_timer(timerHeap()[m_index]) { checkConsistency(); }
void checkConsistency(int offset = 0) const { ASSERT_UNUSED(offset, m_index + offset >= 0); ASSERT_UNUSED(offset, m_index + offset <= static_cast<int>(timerHeap().size())); }