Beispiel #1
0
int huffmanWeight(Tree** heap, int n) {
    heapify(heap, n);
    while(n > 1) {
        Tree* huff =createHuffmanNode();
        huff->left = heapDelete(heap, n--);
        huff->right = heapDelete(heap, n--);
        huff->weight = huff->left->weight + huff->right->weight;
        heapAdd(heap, n++, huff);
    }
    
    return weighting(heap[0]);
}
Beispiel #2
0
void TimerBase::setNextFireTime(double newTime)
{
    ASSERT(m_thread == currentThread());

    // Keep heap valid while changing the next-fire time.
    double oldTime = m_nextFireTime;
    if (oldTime != newTime) {
        m_nextFireTime = newTime;
        static unsigned currentHeapInsertionOrder;
        m_heapInsertionOrder = currentHeapInsertionOrder++;

        bool wasFirstTimerInHeap = m_heapIndex == 0;

        if (oldTime == 0)
            heapInsert();
        else if (newTime == 0)
            heapDelete();
        else if (newTime < oldTime)
            heapDecreaseKey();
        else
            heapIncreaseKey();

        bool isFirstTimerInHeap = m_heapIndex == 0;

        if (wasFirstTimerInHeap || isFirstTimerInHeap)
            threadGlobalData().threadTimers().updateSharedTimer();
    }

    checkConsistency();
}
Beispiel #3
0
void TimerBase::setNextFireTime(double newTime)
{
    // Keep heap valid while changing the next-fire time.

    if (timersReadyToFire)
        timersReadyToFire->remove(this);

    double oldTime = m_nextFireTime;
    if (oldTime != newTime) {
        m_nextFireTime = newTime;

        bool wasFirstTimerInHeap = m_heapIndex == 0;

        if (oldTime == 0)
            heapInsert();
        else if (newTime == 0)
            heapDelete();
        else if (newTime < oldTime)
            heapDecreaseKey();
        else
            heapIncreaseKey();

        bool isFirstTimerInHeap = m_heapIndex == 0;

        if (wasFirstTimerInHeap || isFirstTimerInHeap)
            updateSharedTimer();
    }

    checkConsistency();
}
Beispiel #4
0
void*
heapFirst(HEAP heap)
{
    DBG(debug("heapFirst(heap=%p)\n",heap));

    return heapDelete(heap,0);
}
Beispiel #5
0
void TimerBase::updateHeapIfNeeded(double oldTime)
{
    if (m_nextFireTime && hasValidHeapPosition())
        return;
#if ENABLE(ASSERT)
    int oldHeapIndex = m_heapIndex;
#endif
    if (!oldTime)
        heapInsert();
    else if (!m_nextFireTime)
        heapDelete();
    else if (m_nextFireTime < oldTime)
        heapDecreaseKey();
    else
        heapIncreaseKey();
    ASSERT(m_heapIndex != oldHeapIndex);
    ASSERT(!inHeap() || hasValidHeapPosition());
}