APM: Sparse arrays

Brian Michalk michalk at awpi.com
Thu Jul 10 08:00:44 CDT 2003


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.




More information about the Austin mailing list