1
- (* TEST
2
- *)
3
-
4
- (* CR ocaml 5 runtime: [String] will gain a [seeded_hash]
5
- function, implemented in the OCaml 5 runtime. When that
6
- happens, we should checkout this test to [tip-5].
7
- *)
1
+ (* TEST *)
8
2
9
3
(* Hashtable operations, using maps as a reference *)
10
4
11
5
open Printf
12
6
13
- module Test (H : Hashtbl.S ) (M : Map.S with type key = H.key ) = struct
7
+ module Test (H : Hashtbl.SeededS ) (M : Map.S with type key = H.key ) = struct
14
8
15
9
let incl_mh m h =
16
10
try
@@ -90,31 +84,31 @@ module SS = struct
90
84
type t = string
91
85
let compare (x :t ) (y :t ) = Stdlib. compare x y
92
86
let equal (x :t ) (y :t ) = x= y
93
- let hash = Hashtbl. hash
87
+ let seeded_hash = Hashtbl. seeded_hash
94
88
end
95
89
module SI = struct
96
90
type t = int
97
91
let compare (x :t ) (y :t ) = Stdlib. compare x y
98
92
let equal (x :t ) (y :t ) = x= y
99
- let hash = Hashtbl. hash
93
+ let seeded_hash = Hashtbl. seeded_hash
100
94
end
101
95
module SSP = struct
102
96
type t = string * string
103
97
let compare (x :t ) (y :t ) = Stdlib. compare x y
104
98
let equal (x :t ) (y :t ) = x= y
105
- let hash = Hashtbl. hash
99
+ let seeded_hash = Hashtbl. seeded_hash
106
100
end
107
101
module SSL = struct
108
102
type t = string list
109
103
let compare (x :t ) (y :t ) = Stdlib. compare x y
110
104
let equal (x :t ) (y :t ) = x= y
111
- let hash = Hashtbl. hash
105
+ let seeded_hash = Hashtbl. seeded_hash
112
106
end
113
107
module SSA = struct
114
108
type t = string array
115
109
let compare (x :t ) (y :t ) = Stdlib. compare x y
116
110
let equal (x :t ) (y :t ) = x= y
117
- let hash = Hashtbl. hash
111
+ let seeded_hash = Hashtbl. seeded_hash
118
112
end
119
113
120
114
module MS = Map. Make (SS )
@@ -126,11 +120,11 @@ module MSA = Map.Make(SSA)
126
120
127
121
(* Generic hash wrapped as a functorial hash *)
128
122
129
- module HofM (M : Map.S ) : Hashtbl. S with type key = M. key =
123
+ module HofM (M : Map.S ) : Hashtbl. SeededS with type key = M. key =
130
124
struct
131
125
type key = M .key
132
126
type 'a t = (key , 'a ) Hashtbl .t
133
- let create s = Hashtbl. create s
127
+ let create ? random : bool s = Hashtbl. create s
134
128
let clear = Hashtbl. clear
135
129
let reset = Hashtbl. reset
136
130
let copy = Hashtbl. copy
@@ -161,13 +155,22 @@ module HSL = HofM(MSL)
161
155
162
156
(* Specific functorial hashes *)
163
157
164
- module HS2 = Hashtbl. Make (SS )
165
- module HI2 = Hashtbl. Make (SI )
158
+ module HS2 = Hashtbl. MakeSeeded (SS )
159
+ module HS3 = Hashtbl. MakeSeeded (String )
160
+ module HI2 = Hashtbl. MakeSeeded (SI )
161
+
162
+ (* Specific weak functorial hashes *)
163
+ module WS = Ephemeron.K1. MakeSeeded (SS )
164
+ module WSP1 = Ephemeron.K1. MakeSeeded (SSP )
165
+ module WSP2 = Ephemeron.K2. MakeSeeded (SS )(SS )
166
+ module WSL = Ephemeron.K1. MakeSeeded (SSL )
167
+ module WSA = Ephemeron.Kn. MakeSeeded (SS )
166
168
167
169
(* Instantiating the test *)
168
170
169
171
module TS1 = Test (HS1 )(MS )
170
172
module TS2 = Test (HS2 )(MS )
173
+ module TS3 = Test (HS3 )(MS )
171
174
module TI1 = Test (HI1 )(MI )
172
175
module TI2 = Test (HI2 )(MI )
173
176
module TSP = Test (HSP )(MSP )
@@ -244,11 +247,12 @@ let _ =
244
247
TS1. test d;
245
248
printf " -- Strings, functorial interface\n %!" ;
246
249
TS2. test d;
250
+ printf " -- Strings, functorial(String) interface\n %!" ;
251
+ TS3. test d;
247
252
printf " -- Pairs of strings\n %!" ;
248
253
TSP. test (pair_data d);
249
254
printf " -- Lists of strings\n %!" ;
250
255
TSL. test (list_data d)
251
- ;;
252
256
253
257
254
258
let () =
0 commit comments