memorize

Crates.iomemorize
lib.rsmemorize
version2.0.0
sourcesrc
created_at2023-10-30 22:41:52.439871
updated_at2023-11-07 11:13:12.553785
descriptionVersatile and fast closure cacher with support for recursive algorithms
homepage
repositoryhttps://github.com/lbfalvy/memorize
max_upload_size
id1019144
size8,327
Lawrence Bethlenfalvy (lbfalvy)

documentation

README

Cache the return values of an effectless closure in a hashmap. Inspired by the closure_cacher crate, but attempts to provide a more versatile implementation.

use memorize::{cached, Cache};

let demo = cached(|arg, _| arg * 2);
assert_eq!(demo.find(&7), 14);

The second argument is a callback, it can be used for recursion.

use memorize::{cached, Cache};

let demo = cached(|arg, r| match arg {
  1 | 2 => 1,
  n => r(&(n - 1)) + r(&(n - 2)),
});
assert_eq!(demo.find(&15), 610)
Commit count: 3

cargo fmt