Module caching

Source
Expand description

Basic Cacher struct which stores a closure and a hashmap. The hasmap stores key value pairs representing previous function calls.

When the Cacher function is run, it first does a lookup to see if the value has already been calculated. If it has, it returns that value. If it hasn’t, it calculates the value, adds it to the hashmap, and returns it.

Structs§

Cacher
The Cacher struct (Memoization) stores a function and a Hashmap. The HashMap keeps track of previous input and output for the function so that it only ever has to be called once per input. Use for expensive functions.