let resize tbl =
let odata = tbl.data in
let osize = Array.length odata in
let nsize = 2 * osize + 1 in
let nsize =
if nsize <= Sys.max_array_length then nsize else Sys.max_array_length
in
if nsize <> osize then begin
let ndata = Array.create nsize Empty in
let rec insert_bucket = function
Empty -> ()
| Cons(data, rest) ->
insert_bucket rest; (* preserve original order of elements *)
let nidx = data.hkey mod nsize in
ndata.(nidx) <- Cons(data, ndata.(nidx)) in
for i = 0 to osize - 1 do
insert_bucket odata.(i)
done;
tbl.data <- ndata
end