@@ -36,10 +36,10 @@ module GenHashTable = struct
36
36
type 'a container
37
37
val create : t -> 'a -> 'a container
38
38
val hash : int -> t -> int
39
- val equal : t -> 'a container -> equal
39
+ val equal : 'a container -> t -> equal
40
40
val get_data : 'a container -> 'a option
41
41
val get_key : 'a container -> t option
42
- val set_data : 'a container -> 'a -> unit
42
+ val set_key_data : 'a container -> t -> 'a -> unit
43
43
val check_key : 'a container -> bool
44
44
end ) : SeededS with type key = H. t
45
45
= struct
@@ -161,7 +161,7 @@ module GenHashTable = struct
161
161
let rec remove_bucket = function
162
162
| Empty -> Empty
163
163
| Cons (hk , c , next ) when hkey = hk ->
164
- begin match H. equal key c with
164
+ begin match H. equal c key with
165
165
| ETrue -> h.size < - h.size - 1 ; next
166
166
| EFalse -> Cons (hk, c, remove_bucket next)
167
167
| EDead ->
@@ -182,7 +182,7 @@ module GenHashTable = struct
182
182
| Empty ->
183
183
raise Not_found
184
184
| Cons (hk , c , rest ) when hkey = hk ->
185
- begin match H. equal key c with
185
+ begin match H. equal c key with
186
186
| ETrue ->
187
187
begin match H. get_data c with
188
188
| None ->
@@ -208,7 +208,7 @@ module GenHashTable = struct
208
208
let rec find_in_bucket = function
209
209
| Empty -> []
210
210
| Cons (hk , c , rest ) when hkey = hk ->
211
- begin match H. equal key c with
211
+ begin match H. equal c key with
212
212
| ETrue -> begin match H. get_data c with
213
213
| None ->
214
214
find_in_bucket rest
@@ -228,13 +228,8 @@ module GenHashTable = struct
228
228
let rec replace_bucket = function
229
229
| Empty -> raise Not_found
230
230
| Cons (hk , c , next ) when hkey = hk ->
231
- begin match H. equal key c with
232
- | ETrue -> begin match H. get_data c with
233
- | None ->
234
- (* * This case is not impossible, cf remove *)
235
- replace_bucket next
236
- | Some d -> H. set_data c info
237
- end
231
+ begin match H. equal c key with
232
+ | ETrue -> H. set_key_data c key info
238
233
| EFalse | EDead -> replace_bucket next
239
234
end
240
235
| Cons (_ ,_ ,next ) -> replace_bucket next
@@ -255,7 +250,7 @@ module GenHashTable = struct
255
250
| Empty ->
256
251
false
257
252
| Cons (hk , c , rest ) when hk = hkey ->
258
- begin match H. equal key c with
253
+ begin match H. equal c key with
259
254
| ETrue -> true
260
255
| EFalse | EDead -> mem_in_bucket rest
261
256
end
@@ -403,7 +398,7 @@ module K1 = struct
403
398
set_key c k;
404
399
c
405
400
let hash = H. hash
406
- let equal k c =
401
+ let equal c k =
407
402
(* * {!get_key_copy} is not used because the equality of the user can be
408
403
the physical equality *)
409
404
match get_key c with
@@ -412,7 +407,10 @@ module K1 = struct
412
407
if H. equal k k' then GenHashTable. ETrue else GenHashTable. EFalse
413
408
let get_data = get_data
414
409
let get_key = get_key
415
- let set_data = set_data
410
+ let set_key_data c k d =
411
+ unset_data c;
412
+ set_key c k;
413
+ set_data c d
416
414
let check_key = check_key
417
415
end )
418
416
@@ -479,7 +477,7 @@ module K2 = struct
479
477
c
480
478
let hash seed (k1 ,k2 ) =
481
479
H1. hash seed k1 + H2. hash seed k2 * 65599
482
- let equal (k1 ,k2 ) c =
480
+ let equal c (k1 ,k2 ) =
483
481
match get_key1 c, get_key2 c with
484
482
| None , _ | _ , None -> GenHashTable. EDead
485
483
| Some k1' , Some k2' ->
@@ -490,7 +488,10 @@ module K2 = struct
490
488
match get_key1 c, get_key2 c with
491
489
| None , _ | _ , None -> None
492
490
| Some k1' , Some k2' -> Some (k1', k2')
493
- let set_data = set_data
491
+ let set_key_data c (k1 ,k2 ) d =
492
+ unset_data c;
493
+ set_key1 c k1; set_key2 c k2;
494
+ set_data c d
494
495
let check_key c = check_key1 c && check_key2 c
495
496
end )
496
497
@@ -554,7 +555,7 @@ module Kn = struct
554
555
h := H. hash seed k.(i) * 65599 + ! h;
555
556
done ;
556
557
! h
557
- let equal k c =
558
+ let equal c k =
558
559
let len = Array. length k in
559
560
let len' = length c in
560
561
if len != len' then GenHashTable. EFalse
@@ -589,7 +590,12 @@ module Kn = struct
589
590
in
590
591
let a = Array. make len k0 in
591
592
fill a (len-1 )
592
- let set_data = set_data
593
+ let set_key_data c k d =
594
+ unset_data c;
595
+ for i= 0 to Array. length k - 1 do
596
+ set_key c i k.(i);
597
+ done ;
598
+ set_data c d
593
599
let check_key c =
594
600
let rec check c i =
595
601
i < 0 || (check_key c i && check c (i-1 )) in
0 commit comments