Пример #1
0
// Heapify
VOID
HeapMake(PHeap Heap)
{
	ULONG i;
	if (Heap->Used < 2)
		return;
	i = Parent(Heap->Used - 1);
	while (i != 0)
	{
		HeapSiftDown(Heap, i);
		i--;
	}
	HeapSiftDown(Heap, 0);
}
Пример #2
0
VOID
HeapIncreaseValue(PHeap Heap, ULONG HeapIndex, HEAP_VAL_T Inc)
{
	if (Inc == 0)
		return;
	Heap->Entries[HeapIndex]->Value += Inc;
	#ifdef MIN_HEAP
		HeapSiftDown(Heap, HeapIndex);
	#else
		HeapSiftUp(Heap, HeapIndex);
	#endif
}
Пример #3
0
VOID
HeapZeroValue(PHeap Heap, ULONG HeapIndex)
{
	if (Heap->Entries[HeapIndex]->Value)
	{
		Heap->Entries[HeapIndex]->Value = 0;
		#ifdef MIN_HEAP
			HeapSiftUp(Heap, HeapIndex);
		#else
			HeapSiftDown(Heap, HeapIndex);
		#endif
	}
}
Пример #4
0
LKH::LKHAlg::Node *HeapDeleteMin(LKH::LKHAlg *Alg)
{
    LKH::LKHAlg::Node *Remove;

    if (!*HeapCount)
        return 0;
    Remove = Alg->Heap[1];
    Alg->Heap[1] = Alg->Heap[(*HeapCount)--];
    Alg->Heap[1]->Loc = 1;
	HeapSiftDown(Alg->Heap[1],Alg);
    Remove->Loc = 0;
    return Remove;
}
Пример #5
0
void HeapDelete(LKH::LKHAlg::Node * N,LKH::LKHAlg *Alg)
{
    int Loc = N->Loc;
    if (!Loc)
        return;
    Alg->Heap[Loc] = Alg->Heap[(*HeapCount)--];
    Alg->Heap[Loc]->Loc = Loc;
    if (Alg->Heap[Loc]->Rank > N->Rank)
		HeapSiftDown(Alg->Heap[Loc],Alg);
    else
		HeapSiftUp(Alg->Heap[Loc],Alg);
    N->Loc = 0;
}
Пример #6
0
VOID
HeapDecreaseValue(PHeap Heap, ULONG HeapIndex, HEAP_VAL_T Dec)
{
	if (Heap->Entries[HeapIndex]->Value == 0 || Dec == 0)
		return;
	if (Heap->Entries[HeapIndex]->Value > Dec)
		Heap->Entries[HeapIndex]->Value -= Dec;
	else
		Heap->Entries[HeapIndex]->Value = 0;
	#ifdef MIN_HEAP
		HeapSiftUp(Heap, HeapIndex);
	#else
		HeapSiftDown(Heap, HeapIndex);
	#endif
}
Пример #7
0
VOID
HeapSort(PHeap Heap)
{
	ULONG i, Used;
	PHeapEntry* h = Heap->Entries;
	if (Heap->Used < 2)
		return;
	Used = Heap->Used;
	HeapMake(Heap);
	for (i=Used-1; i>0; i--)
	{
		HEAP_ENTRY_SWAP(h, 0, i);
		Heap->Used--;
		HeapSiftDown(Heap, 0);
	}
	Heap->Used = Used;
}
Пример #8
0
VOID
HeapDelete(PHeap Heap, ULONG HeapIndex)
{
	PHeapEntry* h = Heap->Entries;
	if (Heap->Used == 0)
		return;
	Heap->Used--;
	HEAP_ENTRY_SWAP(h, HeapIndex, Heap->Used);

	if (HEAP_ENTRY_COMPARE(h, HeapIndex, Heap->Used))
		HeapSiftDown(Heap, HeapIndex);
	else
		HeapSiftUp(Heap, HeapIndex);

	_HFREE(Heap->Entries[Heap->Used]);
	Heap->Entries[Heap->Used] = NULL;
}
Пример #9
0
void Heapify(LKH::LKHAlg *Alg)
{
    int Loc;
    for (Loc = *HeapCount / 2; Loc >= 1; Loc--)
		HeapSiftDown(Alg->Heap[Loc],Alg);
}