Re: efficiently keeping a short list

2006-07-11 Thread Dr.Ruud
Tom Allison schreef: > I want to keep a short list of the most recently used 'X'. > < 200 elements. > > Is there any suggestions other than to > unshift @recent, $element; > $#recent = $maximum; > > I know this will create a lot of array movement, but I can't think of > anything better off the top

Re: efficiently keeping a short list

2006-07-11 Thread Jay Savage
Yet another victim of the dreaded reply-to On 7/11/06, Jay Savage <[EMAIL PROTECTED]> wrote: On 7/11/06, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: > Jay Savage wrote: > > No thank you, you have change the script from using seconds to fraction > of seconds. If you had done this the first tim

Re: efficiently keeping a short list

2006-07-11 Thread Mr. Shawn H. Corey
Jay Savage wrote: > Not sure what kind of hardware you have, but it takes considerably > less than a second for me. Not counting the sleep(), of course, which > was just to guarantee unique timestamps for the example. Assuming the > data being used for the keys (the "elements") is of a reasonable s

Re: efficiently keeping a short list

2006-07-11 Thread Jay Savage
On 7/10/06, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: Jay Savage wrote: > foreach ('a'..'z') { > $recent{$_} = time; > sleep 1; > } Ouch. The OP did mention his limit was 200. So he must have more than 200 elements to scan. This algorithm will takes at least 3m20s, so it's hard

Re: efficiently keeping a short list

2006-07-11 Thread Jay Savage
On 7/10/06, Mr. Shawn H. Corey <[EMAIL PROTECTED]> wrote: Jay Savage wrote: > foreach ('a'..'z') { > $recent{$_} = time; > sleep 1; > } Ouch. The OP did mention his limit was 200. So he must have more than 200 elements to scan. This algorithm will takes at least 3m20s, so it's hard

Re: efficiently keeping a short list

2006-07-10 Thread Mr. Shawn H. Corey
Jay Savage wrote: > foreach ('a'..'z') { > $recent{$_} = time; > sleep 1; > } Ouch. The OP did mention his limit was 200. So he must have more than 200 elements to scan. This algorithm will takes at least 3m20s, so it's hardly fast (which was one of the points of this exercise). Try

Re: efficiently keeping a short list

2006-07-10 Thread Jay Savage
On 7/10/06, Jay Savage <[EMAIL PROTECTED]> wrote: On 7/10/06, Charles K. Clarkson <[EMAIL PROTECTED]> wrote: > Mr. Shawn H. Corey wrote: > > We could do a unique check only when the array is accessed > instead of every time a value is added. Then we used the cached > result until another ele

Re: efficiently keeping a short list

2006-07-10 Thread Jay Savage
On 7/10/06, Charles K. Clarkson <[EMAIL PROTECTED]> wrote: Mr. Shawn H. Corey wrote: We could do a unique check only when the array is accessed instead of every time a value is added. Then we used the cached result until another element is added. I'd be inclined to to flip that around:

Re: efficiently keeping a short list

2006-07-10 Thread Mr. Shawn H. Corey
Charles K. Clarkson wrote: > Mr. Shawn H. Corey wrote: > > : OK, here's a solution that might be faster. The problem with > : it is as_array() which has to scan the list every time. There > : is not simpler way for it to work. > > We could do a unique check only when the array is accessed > i

RE: efficiently keeping a short list

2006-07-10 Thread Charles K. Clarkson
Mr. Shawn H. Corey wrote: : OK, here's a solution that might be faster. The problem with : it is as_array() which has to scan the list every time. There : is not simpler way for it to work. We could do a unique check only when the array is accessed instead of every time a value is added. Then

Re: efficiently keeping a short list

2006-07-10 Thread Mr. Shawn H. Corey
Mr. Shawn H. Corey wrote: > Mr. Shawn H. Corey wrote: > >>Your solution will only work if $element is unique. Otherwise you will >>have multiple copies of $element on the list, and not the $maximum >>(unique) number of items. >> >>Try: >> >> @recent = grep { ! /^$element$/ } @recent; >> unshift

Re: efficiently keeping a short list

2006-07-10 Thread Mr. Shawn H. Corey
Mr. Shawn H. Corey wrote: > Your solution will only work if $element is unique. Otherwise you will > have multiple copies of $element on the list, and not the $maximum > (unique) number of items. > > Try: > > @recent = grep { ! /^$element$/ } @recent; > unshift @recent, $element; > $#recent

Re: efficiently keeping a short list

2006-07-09 Thread Mr. Shawn H. Corey
Tom Allison wrote: > I want to keep a short list of the most recently used 'X'. > < 200 elements. > > Is there any suggestions other than to > unshift @recent, $element; > $#recent = $maximum; > > I know this will create a lot of array movement, but I can't think of > anything better off the top

efficiently keeping a short list

2006-07-09 Thread Tom Allison
I want to keep a short list of the most recently used 'X'. < 200 elements. Is there any suggestions other than to unshift @recent, $element; $#recent = $maximum; I know this will create a lot of array movement, but I can't think of anything better off the top of my head. You? -- To unsubscri