-- Sink down on the tree and fix the order heap property.

function PriorityQueue:sink()
	local size = self.current_size
	local heap = self.heap
	local i = 1
	
	while (i * 2) <= size do
		local mc = self:min_child(i)

		if heap[i][2] > heap[mc][2] then
			heap[i], heap[mc] = heap[mc], heap[i]
		end

		i = mc
	end
end

function PriorityQueue:min_child(i)
	local base = i * 2
	local above = base + 1
	
	if 
		above > self.current_size 
		or self.heap[base][2] < self.heap[above][2]
	then
		return base
	end
	
	return above
end

local tbl = {}
tbl.__index = tbl
