Commits

camlspotter  committed 72538d9

Hashtbl.alter fix

  • Participants
  • Parent commits d22ae24
  • Branches 2.4.0

Comments (0)

Files changed (1)

File lib/xhashtbl.ml

+open Hashtbl
+
 let replace_list tbl kvs = 
   List.iter (fun (k,v) ->
     Hashtbl.replace tbl k v) kvs
     def
 
 let alter tbl k f =
-  match f (find_opt tbl k) with
-  | None -> Hashtbl.remove tbl k
-  | Some v -> Hashtbl.replace tbl k v
+  let old = find_opt tbl k in
+  match old, f old with
+  | None, None -> ()
+  | _, Some v -> replace tbl k v
+  | Some _, None -> remove tbl k
 
 let concat tbls =
   let t = Hashtbl.create 101 in (* CR jfuruse: fixed *)