On this page:
samritchie-memoizer
linear-memoize
weak-find-equal-args?
weak-find-eqv-args?
weak-find-eq-args?
hash-memoize-1arg
clear-memoizer-tables
the-memoizers
memoizer

2.8 memoize🔗

 (require sicm/general/memoize) package: rktsicm

Memoize has functions for momoization. It also exports some control functions to get statistics on the memoized functions.

The memoized functions generated have the same arity as the original. If the original function was an apply-hook, the memoized function will also be so, with the same apply-hook-extra’s. And any eq-properties that the original function had will also be copied to the new memoized function. None of the memoizers here defined work out of the box for functions that take keyword arguments.

procedure

(samritchie-memoizer func)  procedure?

  func : procedure?
Multiple argument memoizer that guarantees that memorizing two functions that are eq? result in the same memoized function.

procedure

(linear-memoize func [table-size finder])  procedure?

  func : procedure?
  table-size : integer? = 12
  finder : (-> any/c any/c any/c) = weak-find-equal-args?
Multiple argument memoizer that keeps at most table-size elements in memory. Finding previously calculated items is done with finder. A function constructed with weak-finder.

Finder functions to be used together with linear-memoize.

procedure

(hash-memoize-1arg func)  (-> any/c any/c)

  func : (-> any/c any/c)
Multiple argument memoizer for functions of 1 argument.

procedure

(clear-memoizer-tables)  void

Clear all the memoized values from the memoized functions.

procedure

(the-memoizers)  (listof memoizer)

A list of all memoizer’s currently known.

struct

(struct memoizer (fun org type max-table-size info reset))

  fun : procedure?
  org : procedure?
  type : symbol?
  max-table-size : integer?
  info : (-> (list integer? integer? any/c))
  reset : (-> void)
Combines information about a memoized function. memoizer-fun and memoizer-org hold the memoized and original function. The type is a symbol that shows wich memoizing function created the memoized function.

memoizer-info returns a list that consist of two integers, showing how many hits and misses the memoized function has had, and a third argument that holds info about the internal memory of the memoized function.

memoizer-reset returns a function to reset the memory of the memoized function.