Skip to content

Commit

Permalink
[enhance] Set: choose become quicker
Browse files Browse the repository at this point in the history
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
Arthur Milchior authored and Mathieu Barbin committed Jul 11, 2011
1 parent 2258415 commit 6f7b0d3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion libbase/baseSet.ml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libbase/intSet.ml
Expand Up @@ -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
Expand Down

0 comments on commit 6f7b0d3

Please sign in to comment.