Proto/Env: remove {Set,Map}.find

Also replace all the function raising `Not_found` by their `_opt` version.
This commit is contained in:
Grégoire Henry 2018-03-26 11:13:12 +02:00 committed by Benjamin Canou
parent 48cc2e9928
commit afb1e0f260
4 changed files with 4 additions and 27 deletions

View File

@ -56,18 +56,12 @@ module type SET = sig
val partition: (elt -> bool) -> t -> t * t val partition: (elt -> bool) -> t -> t * t
val cardinal: t -> int val cardinal: t -> int
val elements: t -> elt list val elements: t -> elt list
val min_elt: t -> elt
val min_elt_opt: t -> elt option val min_elt_opt: t -> elt option
val max_elt: t -> elt
val max_elt_opt: t -> elt option val max_elt_opt: t -> elt option
val choose: t -> elt
val choose_opt: t -> elt option val choose_opt: t -> elt option
val split: elt -> t -> t * bool * t val split: elt -> t -> t * bool * t
val find: elt -> t -> elt
val find_opt: elt -> t -> elt option val find_opt: elt -> t -> elt option
val find_first: (elt -> bool) -> t -> elt
val find_first_opt: (elt -> bool) -> t -> elt option val find_first_opt: (elt -> bool) -> t -> elt option
val find_last: (elt -> bool) -> t -> elt
val find_last_opt: (elt -> bool) -> t -> elt option val find_last_opt: (elt -> bool) -> t -> elt option
val of_list: elt list -> t val of_list: elt list -> t
end end
@ -95,18 +89,12 @@ module type MAP = sig
val partition: (key -> 'a -> bool) -> 'a t -> 'a t * 'a t val partition: (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
val cardinal: 'a t -> int val cardinal: 'a t -> int
val bindings: 'a t -> (key * 'a) list val bindings: 'a t -> (key * 'a) list
val min_binding: 'a t -> (key * 'a)
val min_binding_opt: 'a t -> (key * 'a) option val min_binding_opt: 'a t -> (key * 'a) option
val max_binding: 'a t -> (key * 'a)
val max_binding_opt: 'a t -> (key * 'a) option val max_binding_opt: 'a t -> (key * 'a) option
val choose: 'a t -> (key * 'a)
val choose_opt: 'a t -> (key * 'a) option val choose_opt: 'a t -> (key * 'a) option
val split: key -> 'a t -> 'a t * 'a option * 'a t val split: key -> 'a t -> 'a t * 'a option * 'a t
val find: key -> 'a t -> 'a
val find_opt: key -> 'a t -> 'a option val find_opt: key -> 'a t -> 'a option
val find_first: (key -> bool) -> 'a t -> key * 'a
val find_first_opt: (key -> bool) -> 'a t -> (key * 'a) option val find_first_opt: (key -> bool) -> 'a t -> (key * 'a) option
val find_last: (key -> bool) -> 'a t -> key * 'a
val find_last_opt: (key -> bool) -> 'a t -> (key * 'a) option val find_last_opt: (key -> bool) -> 'a t -> (key * 'a) option
val map: ('a -> 'b) -> 'a t -> 'b t val map: ('a -> 'b) -> 'a t -> 'b t
val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t

View File

@ -105,18 +105,12 @@ module type SET = sig
val partition: (elt -> bool) -> t -> t * t val partition: (elt -> bool) -> t -> t * t
val cardinal: t -> int val cardinal: t -> int
val elements: t -> elt list val elements: t -> elt list
val min_elt: t -> elt
val min_elt_opt: t -> elt option val min_elt_opt: t -> elt option
val max_elt: t -> elt
val max_elt_opt: t -> elt option val max_elt_opt: t -> elt option
val choose: t -> elt
val choose_opt: t -> elt option val choose_opt: t -> elt option
val split: elt -> t -> t * bool * t val split: elt -> t -> t * bool * t
val find: elt -> t -> elt
val find_opt: elt -> t -> elt option val find_opt: elt -> t -> elt option
val find_first: (elt -> bool) -> t -> elt
val find_first_opt: (elt -> bool) -> t -> elt option val find_first_opt: (elt -> bool) -> t -> elt option
val find_last: (elt -> bool) -> t -> elt
val find_last_opt: (elt -> bool) -> t -> elt option val find_last_opt: (elt -> bool) -> t -> elt option
val of_list: elt list -> t val of_list: elt list -> t
end end
@ -144,18 +138,12 @@ module type MAP = sig
val partition: (key -> 'a -> bool) -> 'a t -> 'a t * 'a t val partition: (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
val cardinal: 'a t -> int val cardinal: 'a t -> int
val bindings: 'a t -> (key * 'a) list val bindings: 'a t -> (key * 'a) list
val min_binding: 'a t -> (key * 'a)
val min_binding_opt: 'a t -> (key * 'a) option val min_binding_opt: 'a t -> (key * 'a) option
val max_binding: 'a t -> (key * 'a)
val max_binding_opt: 'a t -> (key * 'a) option val max_binding_opt: 'a t -> (key * 'a) option
val choose: 'a t -> (key * 'a)
val choose_opt: 'a t -> (key * 'a) option val choose_opt: 'a t -> (key * 'a) option
val split: key -> 'a t -> 'a t * 'a option * 'a t val split: key -> 'a t -> 'a t * 'a option * 'a t
val find: key -> 'a t -> 'a
val find_opt: key -> 'a t -> 'a option val find_opt: key -> 'a t -> 'a option
val find_first: (key -> bool) -> 'a t -> key * 'a
val find_first_opt: (key -> bool) -> 'a t -> (key * 'a) option val find_first_opt: (key -> bool) -> 'a t -> (key * 'a) option
val find_last: (key -> bool) -> 'a t -> key * 'a
val find_last_opt: (key -> bool) -> 'a t -> (key * 'a) option val find_last_opt: (key -> bool) -> 'a t -> (key * 'a) option
val map: ('a -> 'b) -> 'a t -> 'b t val map: ('a -> 'b) -> 'a t -> 'b t
val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t val mapi: (key -> 'a -> 'b) -> 'a t -> 'b t

View File

@ -435,7 +435,7 @@ let empty_map
let map_get let map_get
: type key value. key -> (key, value) map -> value option : type key value. key -> (key, value) map -> value option
= fun k (module Box) -> = fun k (module Box) ->
try Some (Box.OPS.find k (fst Box.boxed)) with Not_found -> None Box.OPS.find_opt k (fst Box.boxed)
let map_update let map_update
: type a b. a -> b option -> (a, b) map -> (a, b) map : type a b. a -> b option -> (a, b) map -> (a, b) map

View File

@ -15,8 +15,9 @@ let get_proposals ctxt =
~init:Protocol_hash.Map.empty ~init:Protocol_hash.Map.empty
~f:(fun (proposal, _delegate) acc -> ~f:(fun (proposal, _delegate) acc ->
let previous = let previous =
try Protocol_hash.Map.find proposal acc match Protocol_hash.Map.find_opt proposal acc with
with Not_found -> 0l in | None -> 0l
| Some x -> x in
Lwt.return (Protocol_hash.Map.add proposal (Int32.succ previous) acc)) Lwt.return (Protocol_hash.Map.add proposal (Int32.succ previous) acc))
let clear_proposals ctxt = let clear_proposals ctxt =