--!native
--!nonstrict
--!optimize 2
-- Compiled with roblox-ts v2.3.0
local TS = _G[script]
local LFUCache = TS.import(script, script.Parent.Parent, "caches", "lfu-cache").LFUCache
local LRUCache = TS.import(script, script.Parent.Parent, "caches", "lru-cache").LRUCache
--[[
	*
	 * An unchecked memoization function. Will retain memoized data forever.
	 *
	 * @param memoizeFunction
	 * @returns
	 
]]
local function memoize(memoizeFunction)
	local cache = {}
	local function memoized(index)
		local _index = index
		local cached = cache[_index]
		if cached ~= nil then
			return cached
		end
		local result = memoizeFunction(index)
		local _index_1 = index
		cache[_index_1] = result
		return result
	end
	return memoized
end
--[[
	*
	 * A memoization function that uses the {@linkcode LFUCache} data structure to
	 * free up items that aren't frequently used.
	 *
	 * @param memoizeFunction
	 * @param capacity
	 * @returns
	 
]]
local function memoizeFrequencyCache(memoizeFunction, capacity)
	if capacity == nil then
		capacity = 15
	end
	local cache = LFUCache.new(capacity)
	local function memoized(index)
		local cached = cache:get(index)
		if cached ~= nil then
			return cached
		end
		local result = memoizeFunction(index)
		cache:set(index, result)
		return result
	end
	return memoized
end
--[[
	*
	 * A memoization function that uses the {@linkcode LRUCache} data structure to
	 * free up items that aren't recently used.
	 *
	 * @param memoizeFunction
	 * @param capacity
	 * @returns
	 
]]
local function memoizeRecentCache(memoizeFunction, capacity)
	if capacity == nil then
		capacity = 15
	end
	local cache = LRUCache.new(capacity)
	local function memoized(index)
		local cached = cache:get(index)
		if cached ~= nil then
			return cached
		end
		local result = memoizeFunction(index)
		cache:set(index, result)
		return result
	end
	return memoized
end
return {
	memoize = memoize,
	memoizeFrequencyCache = memoizeFrequencyCache,
	memoizeRecentCache = memoizeRecentCache,
}
