--!native
--!nonstrict
--!optimize 2
-- Compiled with roblox-ts v2.3.0
local GraphVertex
do
	GraphVertex = setmetatable({}, {
		__tostring = function()
			return "GraphVertex"
		end,
	})
	GraphVertex.__index = GraphVertex
	function GraphVertex.new(...)
		local self = setmetatable({}, GraphVertex)
		return self:constructor(...) or self
	end
	function GraphVertex:constructor(value)
		self.value = value
		self.degree = 0
		self.edges = {}
		if value == nil then
			error("value must be defined")
		end
	end
	function GraphVertex:addEdge(graphEdge)
		local degree = self.degree
		self.degree = degree + 1
		self.edges[degree + 1] = graphEdge
		return self
	end
	function GraphVertex:deleteEdge(graphEdge)
		local edges = self.edges
		local _graphEdge = graphEdge
		local index = (table.find(edges, _graphEdge) or 0) - 1
		local _condition = index ~= -1
		if _condition then
			-- ▼ Array.unorderedRemove ▼
			local _index = index + 1
			local _length = #edges
			local _value = edges[_index]
			if _value ~= nil then
				edges[_index] = edges[_length]
				edges[_length] = nil
			end
			-- ▲ Array.unorderedRemove ▲
			_condition = _value
		end
		if _condition then
			self.degree -= 1
		end
		return self
	end
	function GraphVertex:getNeighbors()
		local _exp = self.edges
		-- ▼ ReadonlyArray.map ▼
		local _newValue = table.create(#_exp)
		local _callback = function(_param)
			local finishVertex = _param.finishVertex
			local startVertex = _param.startVertex
			return if startVertex == self then finishVertex else startVertex
		end
		for _k, _v in _exp do
			_newValue[_k] = _callback(_v, _k - 1, _exp)
		end
		-- ▲ ReadonlyArray.map ▲
		return _newValue
	end
	function GraphVertex:getEdges()
		return table.clone(self.edges)
	end
	function GraphVertex:getDegree()
		return self.degree
	end
	function GraphVertex:hasEdge(graphEdge)
		local _edges = self.edges
		local _graphEdge = graphEdge
		return table.find(_edges, _graphEdge) ~= nil
	end
	function GraphVertex:hasNeighbor(graphVertex)
		for _, _binding in self.edges do
			local finishVertex = _binding.finishVertex
			local startVertex = _binding.startVertex
			if startVertex == graphVertex or finishVertex == graphVertex then
				return true
			end
		end
		return false
	end
	function GraphVertex:findEdge(graphVertex)
		for _, edge in self.edges do
			if edge.startVertex == graphVertex or edge.finishVertex == graphVertex then
				return edge
			end
		end
		return nil
	end
	function GraphVertex:deleteAllEdges()
		for _, edge in self.edges do
			self:deleteEdge(edge)
		end
		return self
	end
	function GraphVertex:getKey()
		return `{self.value}`
	end
end
GraphVertex.__tostring = function(graphVertex)
	return `{graphVertex.value}`
end
return {
	default = GraphVertex,
}
