48 #ifndef OGDF_BINARY_HEAP2_H
49 #define OGDF_BINARY_HEAP2_H
104 template <
class key,
class HeapObject>
127 void insert(HeapObject& obj, key& p,
int* keyUpdate = 0);
226 void init(
int initSize);
262 HeapEntry(key k,
const HeapObject& ob,
int pos,
int* fp)
292 template <
class key,
class HeapObject>
300 template <
class key,
class HeapObject>
304 m_arraySize = initSize;
305 m_heapArray =
new HeapEntry[arrayBound(m_arraySize)];
307 m_startSize = initSize;
313 template <
class key,
class HeapObject>
316 if (m_heapArray)
delete[] m_heapArray;
326 template <
class key,
class HeapObject>
333 m_heapArray[1].m_pos = 1;
334 if (m_heapArray[1].m_foreignPos != 0)
335 *(m_heapArray[1].m_foreignPos) = 1;
341 while ( (parentIndex(run) >= 1) &&
342 (m_heapArray[parentIndex(run)].m_priority > tempEntry.
m_priority) )
344 m_heapArray[run] = m_heapArray[parentIndex(run)];
345 if (m_heapArray[run].m_foreignPos != 0) *(m_heapArray[run].m_foreignPos) = run;
346 run = parentIndex(run);
349 m_heapArray[run] = tempEntry;
350 m_heapArray[run].
m_pos = run;
351 if (m_heapArray[run].m_foreignPos != 0) *(m_heapArray[run].m_foreignPos) = run;
359 template <
class key,
class HeapObject>
366 m_heapArray[pos].m_pos = pos;
367 if (m_heapArray[pos].m_foreignPos != 0) *(m_heapArray[pos].m_foreignPos) = pos;
371 key sPrio = getPriority(pos);
374 if (hasLeft(pos) && (getPriority(leftChildIndex(pos)) < sPrio) )
376 sIndex = leftChildIndex(pos);
377 sPrio = getPriority(leftChildIndex(pos));
379 if (hasRight(pos) && (getPriority(rightChildIndex(pos)) < sPrio) )
381 sIndex = rightChildIndex(pos);
382 sPrio = getPriority(rightChildIndex(pos));
388 m_heapArray[pos] = m_heapArray[sIndex];
389 m_heapArray[sIndex] = tempEntry;
392 m_heapArray[pos].
m_pos = pos;
393 if (m_heapArray[pos].m_foreignPos != 0) *(m_heapArray[pos].m_foreignPos) = pos;
394 m_heapArray[sIndex].m_pos = sIndex;
395 if (m_heapArray[sIndex].m_foreignPos != 0) *(m_heapArray[sIndex].m_foreignPos) = sIndex;
401 m_heapArray[pos].m_pos = pos;
402 if (m_heapArray[pos].m_foreignPos != 0) *(m_heapArray[pos].m_foreignPos) = pos;
407 template <
class key,
class HeapObject>
417 template <
class key,
class HeapObject>
432 template <
class key,
class HeapObject>
449 for (
int i = 1; i <= HeapBase<key,HeapObject>::m_size ; i++)
450 tempHeap[i] = m_heapArray[i];
451 delete[] m_heapArray;
452 m_heapArray = tempHeap;
453 m_arraySize = lowerArraySize(m_arraySize);
468 template <
class key,
class HeapObject>
477 for (
int i = 1; i <= m_arraySize ; i++)
478 tempHeap[i] = m_heapArray[i];
479 delete[] m_heapArray;
480 m_heapArray = tempHeap;
481 m_arraySize = higherArraySize(m_arraySize);
494 template <
class key,
class HeapObject>
499 if (m_heapArray && !(m_arraySize == rhs.
m_arraySize))
501 delete[] m_heapArray;
515 for (
int i = 1; i <= HeapBase<key,HeapObject>::m_size ; i++)