mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-16 07:46:04 -05:00
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.
This commit is contained in:
parent
ceca7b6343
commit
0c7f4a5d08
1 changed files with 1 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue