APM: Sparse arrays

Wayne Walker wwalker at broadq.com
Thu Jul 10 11:30:07 CDT 2003


On Thu, Jul 10, 2003 at 08:00:44AM -0500, Brian Michalk wrote:
> Let's say I have a sparse array:
> $ary[100]=1;
> $ary[100000]=2;
> $ary[1000000]=3;
> 
> Now, I want to iterate over the array, either from lowest to highest array
> index, and still retain the index of the element returned.  How do I do
> that?

$ary[100]=1;
push @used_elements, 100;
$ary[100000]=2;
push @used_elements, 100000;
$ary[1000000]=3;
push @used_elements, 1000000;

foreach $used_element (sort @used_elements)
{
    do_sumthin($ary($used_element));
}

> foreach $elt (@ary) {
> 	$some_value = $elt;
> 	$the_index = ????????;			# how do I get this information?
> }
> 
> 
> This algorithm is chewing up CPU time, causing the process to take days to
> complete... the dataset is several gigabytes large.
> 
> Using a hash, and sorting the keys will not give me a performance benefit.
> 
> _______________________________________________
> Austin mailing list
> Austin at mail.pm.org
> http://mail.pm.org/mailman/listinfo/austin

-- 

Wayne Walker

www.broadq.com :)  Bringing digital video and audio to the living room



More information about the Austin mailing list