 		while lastIndex > 0 {
 			let parentIndex = _parentIndex(lastIndex)
 			
-			if weights[parentIndex] > weights[lastIndex] {
+			if isWeight(weights[lastIndex], betterThanWeight: weights[parentIndex]) {
 				_swapElements(parentIndex, lastIndex)
 				lastIndex = parentIndex
 			}


import Foundation

public class MinHeap<T: Hashable, W: Comparable> {
	private var array = [T]()
	private var weights = [W]()
	private var elementsToPositions = Dictionary<T, Int>()
	
	private func _parentIndex(index: Int) -> Int {
		return (index - 1) / 2

				return
			}
			
			if isWeight(weights[smallerChildIndex], betterThanWeight: weights[startIndex]) {
				_swapElements(smallerChildIndex, startIndex)
				startIndex = smallerChildIndex
			}
