APM: Sparse arrays

ezra pagel ezra at jdba.org
Thu Jul 10 09:51:40 CDT 2003


# $numberOfElements = scalar @ary;
# $lastArrayIndex = $#ary;

foreach $idx (0..$#ary) {
  $element = $ary[$idx];
  print "$element is at index $idx in \$ary\n";
}

tell us a little more about your data and your hardware environment, and
maybe we can help w/ performance. it shouldn't take days to iterate an
array; i guess it's possible that you've got massive swap space and
you're seeing nothing but i/o thrashing, but that's not likely either.



On Thu, 2003-07-10 at 08:00, 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?
> 
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/austin/attachments/20030710/afb4de16/attachment.htm


More information about the Austin mailing list