Memoization
Posted: Sat Apr 14, 2018 12:55 am
I have a question about how the memoization functions work in the game. So suppose I wanted to cache the number of inhabited planets the current empire has this turn, to avoid iterating through empire.planets to count them every time. Would the following work?
How does the memoizer know when the cache has become stale and the function needs to be called again?
Code: Select all
EmpireProperty.inhabited_planet_count = weak_memoize_1_to_n | function(empire)
local count = 0
for planet ; empire.planets
if planet.inhabited
count += 1
end
end
return count
end
How does the memoizer know when the cache has become stale and the function needs to be called again?