Changeset - r14651:4390ae2296be
[Not reviewed]
master
0 1 0
yexo - 15 years ago 2010-02-25 11:47:44
yexo@openttd.org
(svn r19240) -Codechange: Unify HeapifyUp code (skidd13)
1 file changed with 11 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/misc/binaryheap.hpp
Show inline comments
 
@@ -117,8 +117,17 @@ public:
 
		/* make place for new item */
 
		uint gap = ++m_size;
 
		/* Heapify up */
 
		for (uint parent = gap / 2; (parent > 0) && (new_item < *m_items[parent]); gap = parent, parent /= 2)
 
			m_items[gap] = m_items[parent];
 
		while (gap > 1) {
 
			/* compare [gap] with its parent */
 
			uint parent = gap / 2;
 
			if (new_item < *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;
 
		CheckConsistency();
 
	}
0 comments (0 inline, 0 general)