| Crates.io | Memoirs |
| lib.rs | Memoirs |
| version | 0.0.1 |
| created_at | 2014-12-03 12:31:46.174321+00 |
| updated_at | 2015-12-11 23:54:10.497015+00 |
| description | Memoization functions for Rust |
| homepage | |
| repository | https://github.com/Inspiravetion/Memoirs |
| max_upload_size | |
| id | 450 |
| size | 1,121,092 |
Memoization Functions for Rust
#![feature(phase)]
#![feature(unboxed_closures)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#[phase(plugin)]
extern crate memoirs_mac;
extern crate memoirs;
#[phase(plugin)]
extern crate lazy_static;
static mut count : int = 0;
//not thread safe
memoize!(
fn double(i : int) -> int {
unsafe { count += 1 };
2 * i
}
)
//protected by std::mutex::Mutex
memoize_sync!(
fn triple(i : int) -> int {
unsafe { count += 1 };
3 * i
}
)
#[test]
fn basic_test() {
assert!(2 == double(1));
assert!(4 == double(2));
assert!(6 == double(3));
assert!(unsafe { count } == 3);
assert!(2 == double(1));
assert!(4 == double(2));
assert!(6 == double(3));
assert!(unsafe { count } == 3);
assert!(8 == double(4));
assert!(8 == double(4));
assert!(unsafe { count } == 4);
}