Module Maki__.Maki_utils.Cache

Cache

type 'a equal = 'a ‑> 'a ‑> bool
type 'a hash = 'a ‑> int
type ('a, 'b) t
val get : ('a'bt ‑> 'a ‑> 'b option
val set : ('a'bt ‑> 'a ‑> 'b ‑> unit
val clear : (__t ‑> unit

Clear the content of the cache

val with_cache : ('a'bt ‑> ('a ‑> 'b) ‑> 'a ‑> 'b

with_cache c f behaves like f, but caches calls to f in the cache c. It always returns the same value as f x, if f x returns, or raise the same exception. However, f may not be called if x is in the cache.

val size : (__t ‑> int

Size of the cache (number of entries). At most linear in the number of entries.

val iter : ('a'bt ‑> ('a ‑> 'b ‑> unit) ‑> unit

Iterate on cached values. Should yield size cache pairs.

val replacing : ?⁠eq:'a equal ‑> ?⁠hash:'a hash ‑> int ‑> ('a'bt

Replacing cache of the given size. Equality and hash functions can be parametrized. It's a hash table that handles collisions by replacing the old value with the new (so a cache entry is evicted when another entry with the same hash (modulo size) is added). Never grows wider than the given size.