Utiliser compare x y = 0 au lieu de x = y lorsqu'on compare des cles qui peuvent etre le flottant nan

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5962 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2003-11-21 16:04:26 +00:00
parent c4c06a135d
commit f009490d09
2 changed files with 14 additions and 12 deletions

View File

@ -74,7 +74,7 @@ let remove h key =
Empty ->
Empty
| Cons(k, i, next) ->
if k = key
if compare k key = 0
then begin h.size <- pred h.size; next end
else Cons(k, i, remove_bucket next) in
let i = (hash key) mod (Array.length h.data) in
@ -84,28 +84,30 @@ let rec find_rec key = function
Empty ->
raise Not_found
| Cons(k, d, rest) ->
if key = k then d else find_rec key rest
if compare key k = 0 then d else find_rec key rest
let find h key =
match h.data.((hash key) mod (Array.length h.data)) with
Empty -> raise Not_found
| Cons(k1, d1, rest1) ->
if key = k1 then d1 else
if compare key k1 = 0 then d1 else
match rest1 with
Empty -> raise Not_found
| Cons(k2, d2, rest2) ->
if key = k2 then d2 else
if compare key k2 = 0 then d2 else
match rest2 with
Empty -> raise Not_found
| Cons(k3, d3, rest3) ->
if key = k3 then d3 else find_rec key rest3
if compare key k3 = 0 then d3 else find_rec key rest3
let find_all h key =
let rec find_in_bucket = function
Empty ->
[]
| Cons(k, d, rest) ->
if k = key then d :: find_in_bucket rest else find_in_bucket rest in
if compare k key = 0
then d :: find_in_bucket rest
else find_in_bucket rest in
find_in_bucket h.data.((hash key) mod (Array.length h.data))
let replace h key info =
@ -113,7 +115,7 @@ let replace h key info =
Empty ->
raise Not_found
| Cons(k, i, next) ->
if k = key
if compare k key = 0
then Cons(k, info, next)
else Cons(k, i, replace_bucket next) in
let i = (hash key) mod (Array.length h.data) in
@ -130,7 +132,7 @@ let mem h key =
| Empty ->
false
| Cons(k, d, rest) ->
k = key || mem_in_bucket rest in
compare k key = 0 || mem_in_bucket rest in
mem_in_bucket h.data.((hash key) mod (Array.length h.data))
let iter f h =

View File

@ -134,7 +134,7 @@ let rec exists2 p l1 l2 =
let rec mem x = function
[] -> false
| a::l -> a = x || mem x l
| a::l -> compare a x = 0 || mem x l
let rec memq x = function
[] -> false
@ -142,7 +142,7 @@ let rec memq x = function
let rec assoc x = function
[] -> raise Not_found
| (a,b)::l -> if a = x then b else assoc x l
| (a,b)::l -> if compare a x = 0 then b else assoc x l
let rec assq x = function
[] -> raise Not_found
@ -150,7 +150,7 @@ let rec assq x = function
let rec mem_assoc x = function
| [] -> false
| (a, b) :: l -> a = x || mem_assoc x l
| (a, b) :: l -> compare a x = 0 || mem_assoc x l
let rec mem_assq x = function
| [] -> false
@ -158,7 +158,7 @@ let rec mem_assq x = function
let rec remove_assoc x = function
| [] -> []
| (a, b as pair) :: l -> if a = x then l else pair :: remove_assoc x l
| (a, b as pair) :: l -> if compare a x = 0 then l else pair :: remove_assoc x l
let rec remove_assq x = function
| [] -> []