From 9d2e369732d62650fc755be5cedddfba5409e866 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 4 Feb 2015 12:57:36 +0100 Subject: [PATCH] document some invariants in CCCache (see #38) --- src/data/CCCache.ml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/data/CCCache.ml b/src/data/CCCache.ml index 2c1d152e..f5c85cd3 100644 --- a/src/data/CCCache.ml +++ b/src/data/CCCache.ml @@ -33,6 +33,13 @@ let default_hash_ = Hashtbl.hash (** {2 Value interface} *) +(** Invariants: + - after [cache.set x y], [get cache x] must return [y] or raise [Not_found] + - [cache.set x y] is only called if [get cache x] fails, never if [x] is already bound + - [cache.size()] must be positive and correspond to the number of items in [cache.iter] + - [cache.iter f] calls [f x y] with every [x] such that [cache.get x = y] + - after [cache.clear()], [cache.get x] fails for every [x] +*) type ('a,'b) t = { set : 'a -> 'b -> unit; get : 'a -> 'b; (* or raise Not_found *)