1. Testing a sequence

I'm writing an add on to a program which needs a 'virtual' set of flags
which I'm setting up as elements of a length 12 sequence (VF).
The setting of the flags is not a time worry, but when I want to find out
if any of them have gone high I need to do so real quick.
What I'd like to know is do I have to test every element with a for-next
type loop or can I check if any of the elements has gone 1 by simply
checking -  If vf.
Andrew (Razor) Sharp

new topic     » topic index » view message » categorize

2. Re: Testing a sequence

Why not make each flag as a bit in an integer, eg:

integer flag
flag =.....  --etc
.....
.....
-- Test if any flags are "high...real quick"

if flag then -- yes! a flag is set
else  -- no sad  sorry. all flags are reset (ie zero)
end if


-----Original Message-----
From: Andrew Sharp <asharp at CHILLI.NET.AU>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: Thursday, January 07, 1999 10:48 AM
Subject: Testing a sequence


>I'm writing an add on to a program which needs a 'virtual' set of flags
>which I'm setting up as elements of a length 12 sequence (VF).
>The setting of the flags is not a time worry, but when I want to find out
>if any of them have gone high I need to do so real quick.
>What I'd like to know is do I have to test every element with a for-next
>type loop or can I check if any of the elements has gone 1 by simply
>checking -  If vf.
>Andrew (Razor) Sharp
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: Testing a sequence

Someone stated using the bits of an integer for flagging.
Great idea but they didn't supply code showing how to actually
set the different bits of the integer.  I suggest that method
be tested against the following method for speed.


function loop_test(sequence flag)--He hopes to avoid this.
  for A = 1 to length(flag) do
    if flag[A] then
      return A -- OR use 1 if you don't care where.
    end if
  end for
end function

function find_test(sequence flag)--This should work much better.
  return find(flag, 1) -- OR
--  return (find(flag, 1) > 0) --if you don't care where.
end function

sequence flag

flag = repeat(0, 12)-- You stated length 12.

--HIS actual code would do the flagging that is being done randomly here.
if rand(2) = 1 then
  flag[rand(12)] = rand(2) - 1 --Just might flag it somewhere.
  flag[rand(12)] = rand(2) - 1 --If it did.  It just might flag another or
                               -- it might remove the flag.
end if

? loop_test(flag)--Both will report the same number
? find_test(flag)--But if both are done repeatedly find_test()
                 --Will be faster.

_________________________
"I'm good ! Not god." Lucius L. Hilley III - 1998
_________________________

Lucius L. Hilley III    lhilley at cdc.net
http://www.cdc.net/~lhilley
http://www.dragonvet.com
_________________________
<IMG SRC="http://www.cdc.net/~ceace/images/lu4.jpg">
_________________________

On Wed, 6 Jan 1999 16:23:41 -0500, Andrew Sharp <asharp at CHILLI.NET.AU> wrote:

>I'm writing an add on to a program which needs a 'virtual' set of flags
>which I'm setting up as elements of a length 12 sequence (VF).
>The setting of the flags is not a time worry, but when I want to find out
>if any of them have gone high I need to do so real quick.
>What I'd like to know is do I have to test every element with a for-next
>type loop or can I check if any of the elements has gone 1 by simply
>checking -  If vf.
>Andrew (Razor) Sharp

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu