On Fri, 2006-31-03 at 15:12 -0800, Wagner, David --- Senior Programmer Analyst --- WGO wrote: > I need to handle a set of numbers where I want only the lowest 1000. > There will be no rhyme or reason as the data comes in. I will do some > calculations and take this total against the array or hash or ????? The > number of calculations will be tremendous and either I come up with a way to > handle the lowest 1000 efficiently or I have to write each line which will > come severl 100 million plus and pare it down from there. > > I tried just a simple search and with the 1000 entries, it slowed > everything down to a crawl over time( just started at the front of the array > and worked way through). What the data will be is a total which is the key ( > if same total comes through don't need, throw away) plus the supporting data > which will between 600 to 800 bytes per key. Not large, but when you start > processing the key and either do the move or ??? then starts to add up.
OK, take a deep breath and relax. How are these numbers coming in? One at a time? A batch? Or are they inter-merged with older data? And: Is your program running all the time (no exit)? Or does it start and stop? What you want is a program that keeps track of the lowest 1000. It compares the incoming datum with its highest. If it new datum is higher, discard it. Otherwise, linear search down thru the list until you find it's correct position and place it here; bump everything else up and discard the highest. -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
