From: Brian H. <bri...@ql...> - 2003-05-29 16:34:28
|
On Thu, 29 May 2003, William D. Neumann wrote: > I have a situation where I need to expand the > size of the array to fit the data I will be adding, but I might be adding > the elements out of order, so I can't just call DynArray.add I don't have a problem with a pre-expand, but adding elements out of order doesn't work (at least the way I think they work). If the dynarray has n elements, the elements are numbers 0..n-1 inclusive. The solution is to use a 'a option Dynarray.t. You're null element then becomes None. I dislike exposing the null elements as "valid entries"- to my mind, they're just filler. This is especially important if you consider an int Dynarray.t - is that 0 a real, important 0, or a null element? So I would would fake up a enum that returns n Nones and append it to the dynarray to increase the size. Dynarray.set can then change the Nones to Some x. We might want to consider adding a function in Enum to create an enum that returns so many of a given value, to make this easier. Brian |