function PriorityQueue.sink(u)local m=u.current_size local x=u.heap local d=1 while d*2<=m do local m=u:min_child(d)if x[d][2]>x[m][2]then x[d],x[m]=x[m],x[d]end d=m end end function PriorityQueue.min_child(m,u)local x=u*2 local d=x+1 if d>m.current_size or m.heap[x][2]<m.heap[d][2]then return x end return d end local u={}u.__index=u
-- 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
