memoise
Simple memoization library for rust
Documentation
Find it on docs.rs.
Usage
Add this to your Cargo.toml
:
[]
= "0.3"
And then, just add memoise
attribute to functions you want to memoise:
use memoise;
And you can call it normally:
And run it:
If comment out memoise
attribute, it will not be memoised.
// #[memoise(n <= 100)]
When no bounds for keys given, the cache table Vec
will be allocated dynamically.
use memoise;
// the cache table for `n` is dynamically allocated
_reset
function frees allocated Vec
.
fib; // This allocates cache table for `0..n+1`
fib_reset;
memoise_map
memoises a function by using BTreeMap
.
It is suitable for keys are sparse.
_reset
function also releases all allocated memory.
For more information, you can find a document on docs.rs.