From 0c7f4a5d0801783de9d16fdd80a9709e899a9d71 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Wed, 4 Feb 2015 01:17:23 +0000 Subject: [PATCH] Elements in an LRU cache should be unique If it is not the case, the following code fails miserably: let t = make 2 let () = set t 1 1; set t 1 1; set t 2 2; assert (get t 1 = 1) because in that case the element returned by Hashtbl.find is *not* the first bucket, which is the oldest one. --- src/data/CCCache.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/CCCache.ml b/src/data/CCCache.ml index e65b2e2f..df2f4598 100644 --- a/src/data/CCCache.ml +++ b/src/data/CCCache.ml @@ -269,7 +269,7 @@ module LRU(X:HASH) = struct let set c x y = let len = H.length c.table in assert (len <= c.size); - if len = c.size + if len = c.size || H.mem c.table x then replace_ c x y else insert_ c x y