<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; CHARSET=UTF-8" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>Well, 
the data is a profile of pavement collected from a laser.&nbsp; An individual 
trace can be up to&nbsp;30 meters long at eight samples per millimeter.&nbsp; 
The number of points in a trace varies.&nbsp; I have approximately 5,000 such 
traces.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>I have 
to filter the data to get meaningful information out of it.&nbsp; The culprit 
algorithm in question needs to determine which part of the pavement is actually 
touching the tire.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>Due to 
finite element analysis, I know that approximately 5% of the&nbsp;tire patch 
contact area actually touches the tire.&nbsp; It is this 5% that I'm 
extracting.&nbsp; My&nbsp;filtering window is 50 millimeters long, or 400 
points.&nbsp; I prime a stack, pushing and popping elements into the window, and 
analyze for each individual point in the window (stack)&nbsp; When&nbsp;I find 
the datum representing 5% contact area, I pop the last element and subtract the 
current datum value.&nbsp; Next, I unshift the next point in the trace into the 
stack and repeat all over again.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>This 
algorithm works, and produces repeatable results.&nbsp; However, the 
computational power to use this brute force method is too much.&nbsp; I need to 
convert the data into a histogram, and then start at the high end of the 
histogram, iterating over the indices until I've found 5% of the sample 
population.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>Using 
a hash and sorting the keys does provide a performance increase.&nbsp; 
However,&nbsp;an array is essentially already sorted, and would be ideal if I 
knew what the indices were when I do a foreach over it.&nbsp; I thought about 
using another array to keep track of the indices, and that's probably what I'll 
do.&nbsp; I was just wondering if there was a better method of doing 
it.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003>Someone keeps telling me that theres always another way 
to do it in Perl.</SPAN></FONT></DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN 
class=150241614-10072003></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=#0000ff face=Arial size=2><SPAN class=150241614-10072003>This 
code is not meant to be portable, and if I have to break into the guts to find 
pointers, addresses and break all sorts of encapsulation, then I'll do 
that.</SPAN></FONT></DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px">
  <DIV align=left class=OutlookMessageHeader dir=ltr><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> ezra pagel 
  [mailto:ezra@jdba.org]<BR><B>Sent:</B> Thursday, July 10, 2003 9:50 
  AM<BR><B>To:</B> Brian Michalk<BR><B>Cc:</B> 
  austin-pm@pm.org<BR><B>Subject:</B> Re: APM: Sparse 
  arrays<BR><BR></DIV></FONT># $numberOfElements = scalar @ary;<BR># 
  $lastArrayIndex = $#ary;<BR><BR>foreach $idx (0..$#ary) {<BR>&nbsp; $element = 
  $ary[$idx];<BR>&nbsp; print "$element is at index $idx in 
  \$ary\n";<BR>}<BR><BR>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.<BR><BR></BLOCKQUOTE></BODY></HTML>