Crates.io | memorize |
lib.rs | memorize |
version | 2.0.0 |
source | src |
created_at | 2023-10-30 22:41:52.439871 |
updated_at | 2023-11-07 11:13:12.553785 |
description | Versatile and fast closure cacher with support for recursive algorithms |
homepage | |
repository | https://github.com/lbfalvy/memorize |
max_upload_size | |
id | 1019144 |
size | 8,327 |
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)