mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r19240) -Codechange: Unify HeapifyUp code (skidd13)
This commit is contained in:
parent
71aedf247e
commit
37b4da9f4b
@ -117,8 +117,17 @@ public:
|
|||||||
/* make place for new item */
|
/* make place for new item */
|
||||||
uint gap = ++m_size;
|
uint gap = ++m_size;
|
||||||
/* Heapify up */
|
/* Heapify up */
|
||||||
for (uint parent = gap / 2; (parent > 0) && (new_item < *m_items[parent]); gap = parent, parent /= 2)
|
while (gap > 1) {
|
||||||
|
/* compare [gap] with its parent */
|
||||||
|
uint parent = gap / 2;
|
||||||
|
if (new_item < *m_items[parent]) {
|
||||||
m_items[gap] = m_items[parent];
|
m_items[gap] = m_items[parent];
|
||||||
|
gap = parent;
|
||||||
|
} else {
|
||||||
|
/* we don't need to continue upstairs */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
m_items[gap] = &new_item;
|
m_items[gap] = &new_item;
|
||||||
CheckConsistency();
|
CheckConsistency();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user