local I=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local x=require((I:WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local u=x:GetResource("\083\116\097\116\101\046\080\097\116\104\070\105\110\100\046\071\114\097\112\104\083\111\108\118\101\114")local U=u:Extend()U:SetClassName("\067\097\099\104\101\100\071\114\097\112\104\083\111\108\118\101\114")function U.__new(I)I:InitializeSuper()I.PathCache={}end function U.AddEdge(u,I,x)u.PathCache={}u.super:AddEdge(I,x)end function U.GetShortestDistance(u,I,x)if not u.PathCache[I]then u.PathCache[I]={}end if not u.PathCache[I][x]then u.PathCache[I][x]=u.super:GetShortestDistance(I,x)end return u.PathCache[I][x]end return U
--[[
TheNexusAvenger

Extends the graph solver to add caching.
--]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedStorageProject = require(ReplicatedStorage:WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local GraphSolver = ReplicatedStorageProject:GetResource("State.PathFind.GraphSolver")

local CachedGraphSolver = GraphSolver:Extend()
CachedGraphSolver:SetClassName("CachedGraphSolver")



--[[
Creates a cached graph solver.
--]]
function CachedGraphSolver:__new()
    self:InitializeSuper()

    --Set up the cache.
    self.PathCache = {}
end

--[[
Adds an edge between 2 nodes.
--]]
function CachedGraphSolver:AddEdge(Id1,Id2)
    self.PathCache = {}
    self.super:AddEdge(Id1,Id2)
end

--[[
Returns the shortest distance between 2 nodes.
--]]
function CachedGraphSolver:GetShortestDistance(StartId,EndId)
    --Add the cache entry.
    if not self.PathCache[StartId] then
        self.PathCache[StartId] = {}
    end
    if not self.PathCache[StartId][EndId] then
        self.PathCache[StartId][EndId] = self.super:GetShortestDistance(StartId,EndId)
    end

    --Return the cached entry.
    return self.PathCache[StartId][EndId]
end



return CachedGraphSolver