[sledge] Implement Map.find_and_remove more directly

Summary: No need for exceptions.

Reviewed By: jvillard

Differential Revision: D18736382

fbshipit-source-id: 684bf896c
master
Josh Berdine 5 years ago committed by Facebook Github Bot
parent 30aa8aa3b9
commit 661db9db76

@ -240,17 +240,15 @@ module Map = struct
let equal_m__t (module Elt : Compare_m) equal_v = equal equal_v let equal_m__t (module Elt : Compare_m) equal_v = equal equal_v
let find_and_remove_exn m k = let find_and_remove m k =
let found = ref None in let found = ref None in
let m = let m =
change m k ~f:(fun v -> change m k ~f:(fun v ->
found := v ; found := v ;
None ) None )
in in
match !found with None -> raise Caml.Not_found | Some v -> (v, m) let+ v = !found in
(v, m)
let find_and_remove m k =
try Some (find_and_remove_exn m k) with Caml.Not_found -> None
let find_or_add (type data) map key ~(default : data) ~if_found ~if_added let find_or_add (type data) map key ~(default : data) ~if_found ~if_added
= =

@ -184,7 +184,6 @@ module Map : sig
-> ('k, 'v, 'c) t -> ('k, 'v, 'c) t
-> bool -> bool
val find_and_remove_exn : ('k, 'v, 'c) t -> 'k -> 'v * ('k, 'v, 'c) t
val find_and_remove : ('k, 'v, 'c) t -> 'k -> ('v * ('k, 'v, 'c) t) option val find_and_remove : ('k, 'v, 'c) t -> 'k -> ('v * ('k, 'v, 'c) t) option
val find_or_add : val find_or_add :

Loading…
Cancel
Save