function Heap._HeapifyTopDown(S,V)local W=V*2 local A=W+1 local y if W<=#S and S.Comparator(S[W],S[V])then y=W else y=V end if A<=#S and S.Comparator(S[A],S[y])then y=A end if y~=V then S[V],S[y]=S[y],S[V]S:_HeapifyTopDown(y)end end
--[[ @brief Reshuffles the heap if a given index is larger than one of its children.
--]]
function Heap:_HeapifyTopDown(i)
	local l = i * 2
	local r = l + 1
	local largest
	if l <= #self and self.Comparator(self[l], self[i]) then
		largest = l
	else
		largest = i
	end
	if r <= #self and self.Comparator(self[r], self[largest]) then
		largest = r
	end
	if largest ~= i then
		self[i], self[largest] = self[largest], self[i]
		self:_HeapifyTopDown(largest)
	end
end
