Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 Bib Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

9 Memoisation
 9.1 Memoisation with HashMap

9 Memoisation

datastructures provides simple ways to cache return values of pure functions.

9.1 Memoisation with HashMap

9.1-1 MemoizeFunction
‣ MemoizeFunction( function[, options] )( function )

Returns: A function

MemoizeFunction returns a function which behaves the same as function, except that it caches the return value of function. The cache can be flushed by calling FlushCaches (Reference: FlushCaches).

This function does not promise to never call function more than once for any input -- values may be removed if the cache gets too large, or GAP chooses to flush all caches, or if multiple threads try to calculate the same value simultaneously.

The optional second argument is a record which provides a number of configuration options. The following options are supported.

flush (default true)

If this is true, the cache is emptied whenever FlushCaches (Reference: FlushCaches) is called.

contract (defaults to ReturnTrue (Reference: ReturnTrue))

A function that is called on the arguments given to function. If this function returns false, then errorHandler is called.

errorHandler (defaults to none)

A function to be called when an input that does not fulfil contract is passed to the cache.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 Bib Ind

generated by GAPDoc2HTML