コード例 #1
0
ファイル: 4.3.c プロジェクト: TonyChouZJU/pat-1
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]);
}
コード例 #2
0
ファイル: Timer.cpp プロジェクト: flwh/Alcatel_OT_985_kernel
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();
}
コード例 #3
0
ファイル: Timer.cpp プロジェクト: Crawping/davinci
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();
}
コード例 #4
0
ファイル: heap.c プロジェクト: jiajw0426/easyscada
void*
heapFirst(HEAP heap)
{
    DBG(debug("heapFirst(heap=%p)\n",heap));

    return heapDelete(heap,0);
}
コード例 #5
0
ファイル: Timer.cpp プロジェクト: Rajesh-Veeranki/engine
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());
}