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
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
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
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
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
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
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
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:
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
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
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
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
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
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
14 matches
Mail list logo