Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[enhance] Set: choose become quicker

It gave the minimum element in O(log(n))
Now it works in O(1), giving the element in the top of the tree

Conflicts:

	libbase/baseSetSig.ml
	libbase/intSet.ml
  • Loading branch information...
commit 6f7b0d394061218448b6c256af19aae23463ffa8 1 parent 2258415
Arthur Milchior authored Mathieu Barbin committed
Showing with 4 additions and 2 deletions.
  1. +3 −1 libbase/baseSet.ml
  2. +1 −1  libbase/intSet.ml
View
4 libbase/baseSet.ml
@@ -319,7 +319,9 @@ struct
let add_list l t = List.fold_left (fun acc v -> add v acc) t l
let from_list l = add_list l empty
- let choose = min_elt
+ let choose = function
+ | Empty -> raise Not_found
+ | Node(_, v, _, _) -> v
let rec choose_opt = function
| Empty -> None
View
2  libbase/intSet.ml
@@ -69,7 +69,7 @@ let inter set set' = filter (fun x -> mem x set') set
let diff set set' = filter (fun x -> not (mem x set')) set
let subset (set:t) (set':t) = for_all (fun x -> mem x set') set
-let choose = min_elt
+let choose t = fst (IntMap.choose t)
let choose_opt (set:t) =
match IntMap.choose_opt set with
Please sign in to comment.
Something went wrong with that request. Please try again.