Skip to content

Commit de0fac2

Browse files
committed
Add some documentation
1 parent c8502d2 commit de0fac2

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/cache.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ thread_local! {
1414
static CACHE: RefCell<Cache> = RefCell::new(Cache::default());
1515
}
1616

17-
/// Configure the caching behaviour.
17+
/// Configure the caching and eviction behaviour.
1818
pub fn config(config: Config) {
1919
CACHE.with(|cache| cache.borrow_mut().config = config);
2020
}
2121

22-
/// Configuration for caching behaviour.
22+
/// Configuration for caching and eviction behaviour.
2323
pub struct Config {
2424
max_age: u32,
2525
}
2626

2727
impl Config {
2828
/// The maximum number of evictions an entry can survive without having been
2929
/// used in between.
30+
///
31+
/// Default: 5
3032
pub fn max_age(mut self, age: u32) -> Self {
3133
self.max_age = age;
3234
self
@@ -40,6 +42,10 @@ impl Default for Config {
4042
}
4143

4244
/// Evict cache entries that haven't been used in a while.
45+
///
46+
/// The eviction behaviour can be customized with the [`config`] function.
47+
/// Currently, comemo does not evict the cache automatically (this might
48+
/// change in the future).
4349
pub fn evict() {
4450
CACHE.with(|cache| {
4551
let mut cache = cache.borrow_mut();

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
//! Tracked memoization.
1+
/*!
2+
Memoization on steroids.
3+
4+
A _memoized_ function caches its return values so that it only needs to be
5+
executed once per set of unique arguments.
6+
While this only works for _pure_ functions (functions that don't have side
7+
effects), it can improve performance in many computations.
8+
9+
However, memoization is not a silver bullet.
10+
In many cases, the cache hit rate isn't all that great because arguments are
11+
ever so slightly different.
12+
This is where comemo comes into play:
13+
It let's you reuse a function's output even when called with
14+
_different_ arguments as long as the difference is not observed by the function.
15+
It achieves this by carefully tracking which parts of an argument were actually
16+
accessed during the invocation of a memoized function.
17+
*/
218

319
mod cache;
420
mod constraint;

src/prehashed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use siphasher::sip128::{Hasher128, SipHasher};
1919
/// a == b -> hash(a) == hash(b)
2020
/// ```
2121
/// The inverse implication does not follow from this immediately. However,
22-
/// _comemo_ uses high-quality 128 bit hashes in all places. This reduces the
22+
/// comemo uses high-quality 128 bit hashes in all places. This reduces the
2323
/// risk of a hash collision to an absolute minimum. Therefore, this trait
2424
/// additionally provides `PartialEq` and `Eq` implementations that compare by
2525
/// hash instead of by value.

0 commit comments

Comments
 (0)