Skip to content

Commit

Permalink
#5864: add a find operation to Set.
Browse files Browse the repository at this point in the history
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13211 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
frisch committed Jan 8, 2013
1 parent 42a339e commit a0a55be
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -56,6 +56,7 @@ Feature wishes:
- PR#5769: Allow propagation of Sys.big_endian in native code
- PR#5771: Add primitives for reading 2, 4, 8 bytes in strings and bigarrays
- PR#5774: Add bswap primitives for amd64 and arm
- PR#5864: Add a find operation to Set

Tools:
- OCamlbuild now features a bin_annot tag to generate .cmt files.
Expand Down
4 changes: 2 additions & 2 deletions ocamlbuild/my_std.ml
Expand Up @@ -62,7 +62,7 @@ module Set = struct

module type S = sig
include Set.S
val find : (elt -> bool) -> t -> elt
val find_elt : (elt -> bool) -> t -> elt
val map : (elt -> elt) -> t -> t
val of_list : elt list -> t
val print : formatter -> t -> unit
Expand All @@ -71,7 +71,7 @@ module Set = struct
module Make (M : OrderedTypePrintable) : S with type elt = M.t = struct
include Set.Make(M)
exception Found of elt
let find p set =
let find_elt p set =
try
iter begin fun elt ->
if p elt then raise (Found elt)
Expand Down
2 changes: 1 addition & 1 deletion ocamlbuild/rule.ml
Expand Up @@ -161,7 +161,7 @@ let call builder r =
begin match exists2 List.find Resource.Cache.resource_has_changed r.deps with
| Some r -> (`cache_miss_changed_dep r, false)
| _ ->
begin match exists2 Resources.find Resource.Cache.resource_has_changed dyndeps with
begin match exists2 Resources.find_elt Resource.Cache.resource_has_changed dyndeps with
| Some r -> (`cache_miss_changed_dyn_dep r, false)
| _ ->
begin match cached_digest r with
Expand Down
2 changes: 1 addition & 1 deletion ocamlbuild/signatures.mli
Expand Up @@ -23,7 +23,7 @@ end

module type SET = sig
include Set.S
val find : (elt -> bool) -> t -> elt
val find_elt : (elt -> bool) -> t -> elt
val map : (elt -> elt) -> t -> t
val of_list : elt list -> t
val print : Format.formatter -> t -> unit
Expand Down
1 change: 1 addition & 0 deletions stdlib/moreLabels.mli
Expand Up @@ -159,6 +159,7 @@ module Set : sig
val max_elt : t -> elt
val choose : t -> elt
val split: elt -> t -> t * bool * t
val find: elt -> t -> elt
end
module Make : functor (Ord : OrderedType) -> S with type elt = Ord.t
end
7 changes: 7 additions & 0 deletions stdlib/set.ml
Expand Up @@ -47,6 +47,7 @@ module type S =
val max_elt: t -> elt
val choose: t -> elt
val split: elt -> t -> t * bool * t
val find: elt -> t -> elt
end

module Make(Ord: OrderedType) =
Expand Down Expand Up @@ -348,4 +349,10 @@ module Make(Ord: OrderedType) =

let choose = min_elt

let rec find x = function
Empty -> raise Not_found
| Node(l, v, r, _) ->
let c = Ord.compare x v in
if c = 0 then v
else find x (if c < 0 then l else r)
end
4 changes: 4 additions & 0 deletions stdlib/set.mli
Expand Up @@ -143,6 +143,10 @@ module type S =
strictly greater than [x];
[present] is [false] if [s] contains no element equal to [x],
or [true] if [s] contains an element equal to [x]. *)

val find: elt -> t -> elt
(** [find x s] returns the element of [s] equal to [x], or raise
[Not_found] if no such element exists. *)
end
(** Output signature of the functor {!Set.Make}. *)

Expand Down

0 comments on commit a0a55be

Please sign in to comment.