function Heap._HeapifyTopDown(V,g)local S=g*2 local I=S+1 local J if S<=#V and V.Comparator(V[S],V[g])then J=S else J=g end if I<=#V and V.Comparator(V[I],V[J])then J=I end if J~=g then V[g],V[J]=V[J],V[g]V:_HeapifyTopDown(J)end end

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
