diff --git a/vendors/Red-Black_Trees/PolyMap.ml b/vendors/Red-Black_Trees/PolyMap.ml index 78ab1738c..0ed6e9d6d 100644 --- a/vendors/Red-Black_Trees/PolyMap.ml +++ b/vendors/Red-Black_Trees/PolyMap.ml @@ -23,19 +23,17 @@ let remove key map = let cmp k1 (k2,_) = map.cmp k1 k2 in {map with tree = RB.remove ~cmp key map.tree} -exception Not_found - let find key map = let cmp k1 (k2,_) = map.cmp k1 k2 in try snd (RB.find ~cmp key map.tree) with - RB.Not_found -> raise Not_found + Not_found -> raise Not_found let find_opt key map = try Some (find key map) with Not_found -> None let update key updater map = match updater (find_opt key map) with - | None -> failwith "TODO: RedBlackTrees: remove not implemented" (* TODO: remove key *) + | None -> remove key map | Some v -> add key v map let bindings map = diff --git a/vendors/Red-Black_Trees/PolyMap.mli b/vendors/Red-Black_Trees/PolyMap.mli index 01e0d1468..bff0e87ce 100644 --- a/vendors/Red-Black_Trees/PolyMap.mli +++ b/vendors/Red-Black_Trees/PolyMap.mli @@ -42,8 +42,6 @@ val remove : 'key -> ('key, 'value) t -> ('key, 'value) t [key] in the map [map]. If [key] is not bound in [map], the exception [Not_found] is raised. *) -exception Not_found - val find : 'key -> ('key, 'value) t -> 'value (* The value of the call [find_opt key map] is [Some value] if the key diff --git a/vendors/Red-Black_Trees/PolySet.ml b/vendors/Red-Black_Trees/PolySet.ml index 7bbc3d628..ab26380f2 100644 --- a/vendors/Red-Black_Trees/PolySet.ml +++ b/vendors/Red-Black_Trees/PolySet.ml @@ -17,11 +17,9 @@ let is_empty set = RB.is_empty set.tree let add elt set = {set with tree = RB.add ~cmp:set.cmp RB.New elt set.tree} -exception Not_found - let find elt set = try RB.find ~cmp:set.cmp elt set.tree with - RB.Not_found -> raise Not_found + Not_found -> raise Not_found let find_opt elt set = RB.find_opt ~cmp:set.cmp elt set.tree diff --git a/vendors/Red-Black_Trees/PolySet.mli b/vendors/Red-Black_Trees/PolySet.mli index b76ebfd97..c8eb4b6d4 100644 --- a/vendors/Red-Black_Trees/PolySet.mli +++ b/vendors/Red-Black_Trees/PolySet.mli @@ -38,8 +38,6 @@ val add : 'elt -> 'elt t -> 'elt t function of [set] (see [create]). If [elt] is not in [set], then the exception [Not_found] is raised. *) -exception Not_found - val find : 'elt -> 'elt t -> 'elt (* The call [find_opt elt set] is similar to [find elt set], except diff --git a/vendors/Red-Black_Trees/RedBlack.ml b/vendors/Red-Black_Trees/RedBlack.ml index 4241363dc..f77954d09 100644 --- a/vendors/Red-Black_Trees/RedBlack.ml +++ b/vendors/Red-Black_Trees/RedBlack.ml @@ -67,16 +67,15 @@ let remove : type a b . cmp:(a -> b -> int) -> a -> b t -> b t = fun ~cmp elt tr Int (colour, new_left, lroot, right) ) in let rec bst_delete : a -> b t -> b t = fun elt -> function - | Ext -> failwith "remove in red-black tree: element not found" + | Ext -> raise Not_found | Int (colour, left, root, right) as current -> let c = cmp elt root in if c = 0 then bst_shift_up current else if c < 0 then Int (colour, bst_delete elt left, root, right) else Int (colour, left, root, bst_delete elt right) in - bst_delete elt tree - -exception Not_found + try bst_delete elt tree + with Not_found -> tree let rec find ~cmp elt = function Ext -> raise Not_found diff --git a/vendors/Red-Black_Trees/RedBlack.mli b/vendors/Red-Black_Trees/RedBlack.mli index 9642da8e6..16d1f1a2e 100644 --- a/vendors/Red-Black_Trees/RedBlack.mli +++ b/vendors/Red-Black_Trees/RedBlack.mli @@ -39,8 +39,6 @@ val remove: cmp:('a -> 'b -> int) -> 'a -> 'b t -> 'b t to a node of the tree [t], such that [cmp x y = true]. If none, the exception [Not_found] is raised. *) -exception Not_found - val find: cmp:('a -> 'b -> int) -> 'a -> 'b t -> 'b (* The value of call [find_opt ~cmp x t] is [Some y] if there is an