Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
inline void TimerBase::heapInsert()
{
    ASSERT(!inHeap());
    timerHeap().append(this);
    m_heapIndex = timerHeap().size() - 1;
    heapDecreaseKey();
}
Exemplo n.º 3
0
void TimerBase::heapPopMin()
{
    ASSERT(this == timerHeap().first());
    checkHeapIndex();
    pop_heap(TimerHeapIterator(0), TimerHeapIterator(timerHeap().size()));
    checkHeapIndex();
    ASSERT(this == timerHeap().last());
}
Exemplo n.º 4
0
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());
}
Exemplo n.º 5
0
void TimerBase::heapDeleteMin()
{
    ASSERT(m_nextFireTime == 0);
    heapPopMin();
    timerHeap().removeLast();
    m_heapIndex = -1;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
void TimerBase::heapDecreaseKey()
{
    ASSERT(m_nextFireTime != 0);
    checkHeapIndex();
    TimerBase** heapData = timerHeap().data();
    push_heap(TimerHeapIterator(heapData), TimerHeapIterator(heapData + m_heapIndex + 1), TimerHeapLessThanFunction());
    checkHeapIndex();
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
 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());
 }
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
 void checkConsistency() const
 {
     ASSERT(m_index >= 0);
     ASSERT(m_index < static_cast<int>(timerHeap().size()));
 }
Exemplo n.º 12
0
 explicit TimerHeapElement(int i)
     : m_index(i)
     , m_timer(timerHeap()[m_index])
 { 
     checkConsistency(); 
 }
Exemplo n.º 13
0
 void checkConsistency(int offset = 0) const
 {
     ASSERT_UNUSED(offset, m_index + offset >= 0);
     ASSERT_UNUSED(offset, m_index + offset <= static_cast<int>(timerHeap().size()));
 }