Skip to content
This repository

A utility for creating function-call caches in D.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.md
Octocat-spinner-32 cache.d
Octocat-spinner-32 doc.html
README.md

cache.d

cache.d is a utility for caching function calls in D.

Example

import cache;
import std.stdio;

void main() {
    // makes an empty cache
    Cache!(typeof(&factorial)) cache = createCache(&factorial);

    // excecutes the function
    writeln(cache(3));

    // looks it up in the cache
    writeln(cache(3));
}

ulong factorial(ulong n) {
    ulong r;
    for(r=0; n>0; n--) {
        r *= n;
    }
    return r;
}

Contributing

Pull requests are appreciated.

Something went wrong with that request. Please try again.