At 05:41 PM 8/9/00 +0200, Bart Lateur wrote:
>On Wed, 09 Aug 2000 10:04:15 -0400, Dan Sugalski wrote:
>
> >>5- Compact array storage: RFC still coming
> >
> >I hope this RFC will be "Arrays should be sparse when possible, and
> >compact" and just about nothing else. :)
>
>You mean, something like hashes?

Nope.

>Faster hashes, maybe, with a hash function optimized for numerical
>integer keys.

I was thinking we might keep a bitmap for used/unused cells (with unused 
doubling as undef) and a two-level array pointing to chunks of real 
elements/element pointers.

So, for example, if you did a:

    $foo[$elem];

perl would first check bit $elem to see if that element is in use. If so, 
it'd do a ($elem / chunk_size) to get the index to the chunk pointer in the 
array structure, then access element ($elem % chunk_size) to get a pointer 
to the ultimate thing. (Or the thing itself, if it were an int, say)

Other methods are possible, of course, and which would be a win depends on 
your element distribution. (A linked list would be a win for very sparse 
arrays--$foo[time])

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to