@@ -17,7 +17,6 @@ module Bindings = struct
17
17
structure " cmph_io_adapter_t"
18
18
19
19
let _data = field cmph_io_adapter_t " data" (ptr void)
20
-
21
20
let nkeys = field cmph_io_adapter_t " nkeys" uint32_t
22
21
23
22
let read =
@@ -68,9 +67,7 @@ module Bindings = struct
68
67
foreign " cmph_search" (cmph_t @-> string @-> int @-> returning int )
69
68
70
69
let cmph_destroy = foreign " cmph_destroy" (cmph_t @-> returning void)
71
-
72
70
let cmph_pack = foreign " cmph_pack" (cmph_t @-> ocaml_bytes @-> returning void)
73
-
74
71
let cmph_packed_size = foreign " cmph_packed_size" (cmph_t @-> returning int )
75
72
76
73
let cmph_search_packed =
@@ -81,11 +78,12 @@ exception Error of [ `Empty | `Hash_new_failed of string | `Parameter_range | `F
81
78
[@@ deriving sexp]
82
79
83
80
module KeySet = struct
81
+ (* Unused functions must be retained to prevent garbage collection. *)
84
82
type t = {
85
83
length : int ;
86
- read : unit ptr -> char ptr ptr -> Unsigned .uint32 ptr -> int ;
87
- dispose : unit ptr -> char ptr -> Unsigned .uint32 -> unit ;
88
- rewind : unit ptr -> unit ;
84
+ _read : unit ptr -> char ptr ptr -> Unsigned .uint32 ptr -> int ;
85
+ _dispose : unit ptr -> char ptr -> Unsigned .uint32 -> unit ;
86
+ _rewind : unit ptr -> unit ;
89
87
adapter : (Bindings .cmph_io_adapter_t , [ `Struct ]) structured ptr ;
90
88
}
91
89
@@ -121,12 +119,17 @@ module KeySet = struct
121
119
setf adapter Bindings. read read;
122
120
setf adapter Bindings. dispose dispose;
123
121
setf adapter Bindings. rewind rewind;
124
- { length = Array. length keys; read; dispose; rewind; adapter = addr adapter }
122
+ {
123
+ length = Array. length keys;
124
+ _read = read;
125
+ _dispose = dispose;
126
+ _rewind = rewind;
127
+ adapter = addr adapter;
128
+ }
125
129
end
126
130
127
131
module Config = struct
128
132
type hash = [ `Jenkins | `Count ] [@@ deriving sexp ]
129
-
130
133
type chd_config = { keys_per_bucket : int ; keys_per_bin : int } [@@ deriving sexp ]
131
134
132
135
type algo =
@@ -143,7 +146,7 @@ module Config = struct
143
146
144
147
type t = {
145
148
config : Bindings .cmph_config_t ;
146
- keyset : KeySet .t ;
149
+ _keyset : KeySet .t ;
147
150
mutable freed : bool ;
148
151
}
149
152
@@ -166,7 +169,6 @@ module Config = struct
166
169
| `Chd _ -> " Chd"
167
170
168
171
let default_chd = `Chd { keys_per_bucket = 4 ; keys_per_bin = 1 }
169
-
170
172
let default_chd_ph = `Chd_ph { keys_per_bucket = 4 ; keys_per_bin = 1 }
171
173
172
174
let valid_algo algo keyset =
@@ -193,19 +195,19 @@ module Config = struct
193
195
Bindings. cmph_config_set_graphsize config 0.90 ;
194
196
Bindings. cmph_config_set_algo config (algo_value algo);
195
197
Bindings. cmph_config_set_verbosity config (if verbose then 1 else 0 );
196
- ( match algo with
198
+ (match algo with
197
199
| `Chd c | `Chd_ph c ->
198
200
Bindings. cmph_config_set_b config c.keys_per_bucket;
199
201
Bindings. cmph_config_set_keys_per_bin config c.keys_per_bin
200
- | _ -> () );
201
- { config; keyset; freed = false }
202
+ | _ -> () );
203
+ { config; _keyset = keyset; freed = false }
202
204
203
205
let assert_valid { freed; _ } = if freed then raise @@ Error `Freed
204
206
205
207
let destroy c =
206
208
if not c.freed then (
207
209
Bindings. cmph_config_destroy c.config;
208
- c.freed < - true )
210
+ c.freed < - true )
209
211
210
212
let with_config ?verbose ?algo ?seed keyset f =
211
213
let c = create ?verbose ?algo ?seed keyset in
@@ -257,7 +259,7 @@ module Hash = struct
257
259
Config. destroy c.config;
258
260
if not c.freed then (
259
261
Bindings. cmph_destroy c.hash;
260
- c.freed < - true )
262
+ c.freed < - true )
261
263
262
264
let with_hash c f =
263
265
let h = of_config c in
0 commit comments