From: Nicolas C. <war...@fr...> - 2004-03-21 10:02:32
|
> > Thanks, > > You're welcome :) > > > The CVS have been updated with your changes. To answer more precisely > > to your questions : > > - we could actualy use ints as 16 bits values if we add the API to > > extract them from strings, but we don't :) > > Why not to add this API ? It might also be useful in to improve other > data structures. And why only 16 bits and not 32 ? - We have to write C functions for that API. - 16 bits are currently handled by a single unboxed OCaml int. Using all 32-bits is possible if we box integers -> that means that we will alloc/free a lot of blocks around, that's not efficient. > > - we can't use Pervasives.compare because bitsets might be of > > different sizes but are actually the same integer > > I didn't want to say that Pervasives.compare should be used directly. I > suggested something like that : > > (************************************************************) > let extend t old_size new_size = > let b = bcreate new_size in > bblit !t 0 b 0 old_size; > bfill b old_size (new_size - old_size) 0; > b > > let compare t1 t2 = > let size1 , size2 = blen !t1 , blen !t2 in > if size1 < size2 then > Pervasives.compare (extend t1 size1 size2) !t2 > else if size1 > size2 then > Pervasives.compare !t1 (extend t2 size2 size1) > else > Pervasives.compare !t1 !t2 In this case, I think custom compare function is better since it doesn't require an allocation + a copy. There is not so big speed difference between (correctly written) OCaml code and C when compiled in native mode :) Nicolas Cannasse |