function PriorityQueue.sink(m)local o=m.current_size local j=m.heap local h=1 while h*2<=o do local o=m:min_child(h)if j[h][2]>j[o][2]then j[h],j[o]=j[o],j[h]end h=o end end function PriorityQueue.min_child(o,m)local j=m*2 local h=j+1 if h>o.current_size or o.heap[j][2]<o.heap[h][2]then return j end return h end local m={}m.__index=m

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
