aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotin2007-04-02 09:29:57 +0000
committernotin2007-04-02 09:29:57 +0000
commitc3a45d82e7e1a2aef2957fed62d734e2fe943ef5 (patch)
tree0f2c9849d663be40779f7b5da0776bba12d2062d
parented7f856a9d65519a8d934a17fb7d4cb9211d1e14 (diff)
Intégration de la modification suggérée par Michal Moskal (cf msg sur Coq Club du 31/03/2007)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@9741 85f007b7-540e-0410-9357-904b9bb8a0f7
-rw-r--r--lib/util.ml24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/util.ml b/lib/util.ml
index 38eb88ebfa..66485d5a36 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -296,14 +296,28 @@ let list_try_find f =
try_find_f
let list_uniquize l =
+ let visited = Hashtbl.create 23 in
let rec aux acc = function
- | [] -> List.rev acc
- | h::t -> if List.mem h acc then aux acc t else aux (h::acc) t
+ | h::t -> if Hashtbl.mem visited h then aux acc t else
+ begin
+ Hashtbl.add visited h h;
+ aux (h::acc) t
+ end
+ | [] -> List.rev acc
in aux [] l
-let rec list_distinct = function
- | h::t -> (not (List.mem h t)) && list_distinct t
- | _ -> true
+let rec list_distinct l =
+ let visited = Hashtbl.create 23 in
+ let rec loop = function
+ | h::t ->
+ if Hashtbl.mem visited h then false
+ else
+ begin
+ Hashtbl.add visited h h;
+ loop t
+ end
+ | [] -> true
+ in loop l
let rec list_filter2 f = function
| [], [] as p -> p