function PriorityQueue.new()return setmetatable({heap={},current_size=0},PriorityQueue)end function PriorityQueue.isEmpty(x)return x.current_size==0 end function PriorityQueue.size(x)return x.current_size end function PriorityQueue.swim(x)local C=floor local n=x.heap local k=x.current_size local M=C(k/2)while M>0 do if n[k][2]<n[M][2]then n[k],n[M]=n[M],n[k]end k=M M=C(k/2)end end function PriorityQueue.Push(n,x,C)table.insert(n.heap,{x;C})n.current_size+=1 n:swim()end


function PriorityQueue.new()
	return setmetatable({
		heap = {},
		current_size = 0
	}, PriorityQueue)
end

function PriorityQueue:isEmpty()
	return self.current_size == 0
end

function PriorityQueue:size()
	return self.current_size
end

function PriorityQueue:swim()
	-- Swim up on the tree and fix the order heap property.
	local floor = floor
	local heap = self.heap
	local i = self.current_size
	
	local half = floor(i / 2)
	
	while half > 0 do
		if heap[i][2] < heap[half][2] then
			heap[i], heap[half] = heap[half], heap[i]
		end

		i = half
		half = floor(i / 2)
	end
end

function PriorityQueue:Push(v, p)
    --[[ Put an item on the queue.
    Args:
        v: the item to be stored
        p(number): the priority of the item
    ]]--
	--
	table.insert(self.heap, {v, p})
	self.current_size += 1
	self:swim()
end
