1795c1409cc7acc162cd24f7cae7dff3d326f8dc
1 (**************************************************************************)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the GNU Library General Public License, with the *)
11 (* special exception on linking described in file LICENSE. *)
13 (**************************************************************************)
15 (* $Id: infiniteArray.ml,v 1.2 2010/01/28 14:23:47 npalix Exp $ *)
17 (** This module implements infinite arrays, that is, arrays that grow
18 transparently upon demand. *)
22 mutable table
: 'a array
;
23 mutable extent
: int; (* the index of the greatest [set] ever, plus one *)
27 16384 (* must be non-zero *)
31 table
= Array.make default_size x
;
35 let rec new_length length i
=
39 new_length (2 * length
) i
42 let table = a
.table in
43 let length = Array.length table in
44 if i
>= length then begin
45 let table'
= Array.make (new_length (2 * length) i
) a
.default
in
46 Array.blit
table 0 table'
0 length;
57 a
.extent
<- max
(i
+ 1) a
.extent
63 Array.sub a
.table 0 a
.extent