lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > -----Message d'origine-----
> > De : lua-bounces@bazar2.conectiva.com.br [mailto:lua-
> > bounces@bazar2.conectiva.com.br] De la part de Javier Guerra Giraldez
> > 
> > no.  in fact, having the array part is quite handy to store a desired
> > order on a hashtable (which is intrinsically unsorted).  see how
> > luaExpat reports XML argument lists
> > 
> 
> To be fair, I suppose that a table implementation without the array
> part optimization could in fact be able to store a sorted sequence of
> scalar keys if the hash function yields sorted hashes for scalar keys
> (which is to say the scalars themselves). Thus, to have sorted tables,
> one has to choose between the array part and an ordered hash function
> on scalar keys. So yes, it *is* an implementation detail after all.

You do not need anything specific to sort an array. The order in the
array is instrinsic to the keys (1,2,etc.); it has nothing to do with
the implementation. When sorting, you know that the smaller element must
be at index 1, no matter where/how this index is represented internally.

-- Roberto