On Apr 11, 2007, at 12:39 PM, Fargo Holiday wrote: >>> I need to maintain an integer array to be used as a FIFO stack. I >>> will .append() up to 10000 values, and when the array reaches that >>> size, I will "cut off" the oldest (lowest) 5000 entries. Right now >>> I'm doing this by using .remove() in a loop. >>> >>> The thing needs to be as time-efficient as possible, so I wonder if >>> it would be more efficient if I created a new array and copied over >>> the last 5000, rather than removing the first 5000. >>> >>> Has anybody experience with this kind of operations, so that I don't >>> need to test it on my own? >> >> The fastest solution given what you've described would be an array of >> 10,000 elements (or even a memory block, depending on what types of >> values they are), which you don't resize. Instead, you would keep >> head and tail position values, and maintain everything that way. When >> you reached the end of the array, you'd wrap around the other side. >> > Howdy, > I'm afraid I didn't quite follow what you mean there. Could someone > post > a simple example?
Imagine the 10,000 elements are arranged, not in a line, but in a circle. You keep track of two numbers, representing where in the circle the head and tail of your list are. When these meet, you extract the first 5,000 elements from the list, moving the tail up. Now, because it's a ring, you have room in front of the head of the list for another 5,000 elements. Lather, rinse and repeat. Regards, Guyren G Howe Relevant Logic LLC guyren-at-relevantlogic.com ~ http://relevantlogic.com REALbasic, PHP, Ruby/Rails, Python programming PostgreSQL, MySQL database design and consulting Technical writing and training _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
