function PriorityQueue.new()return setmetatable({heap={};current_size=0},PriorityQueue)end function PriorityQueue.isEmpty(U)return U.current_size==0 end function PriorityQueue.size(U)return U.current_size end function PriorityQueue.swim(U)local Z=floor local f=U.heap local Q=U.current_size local K=Z(Q/2)while K>0 do if f[Q][2]<f[K][2]then f[Q],f[K]=f[K],f[Q]end Q=K K=Z(Q/2)end end function PriorityQueue.Push(f,U,Z)table.insert(f.heap,{U,Z})f.current_size+=1 f:swim()end
-- // NOTE: This module is not written by me, but slightly modified \\ --

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
