in reply to Re: Sparse arrays?
in thread Sparse arrays?

I have always thought that sparse arrays was just another term for a hash.

No. Hashes are unordered collections. You can impose an order on them by requiring ordered keys and then use a hash to implement a sparse array. Additional information, such as a normal dense array containing the sorted hash keys, are needed in order to allow iteration though.

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: Sparse arrays?
by Fletch (Bishop) on Dec 18, 2002 at 18:02 UTC
    Additional information, such as a normal dense array containing the sorted hash keys, are needed in order to allow iteration though.

    Of course you can obtain that on the fly trivially with foreach( sort { $a <=> $b } keys %sparse ). It's really more of an efficiency question whether you want to keep that seperately or do it each time (and either way could be done transparently with a tied array).