On Sunday, August 22, 2004, at 04:27 PM, Alex Tweedly wrote:

At 15:46 22/08/2004 -0700, Mark Brownell wrote:


So let's say that you have hundreds of points either in an array or comma delimited. What would be the fastest way to get the value of the item just less than 100 in this following example?

1, 34, 67, 99, 109, 121, 133, 144, 155, (answer = item 4) -- 99

Would I have to loop through each one checking each during a repeat for the last item less-than 100 or is there a faster way to get the value in item 4. Every time I can drop a repeat loop seems to be a way to optimize the result based on speed issues.

If you have only have hundreds of points, then a loop may not be too bad.

It was just an example to show getting item 4. In some cases I have hundreds out of millions.


[snip]
But a more fundamental question - why would you want to know that ? :-)

I wouldn't want to know that. :-) I have exactly what I need in offset() repeat loops. It's just too slow.


I'd guess it's because you have something like ....

   put the offsets of "<a>" of theText into tOff1
   put the offsets of "</a>" of theText into tOff2

and then your working through tOff2, find a value of 100 and want to find the matching (i.e. preceding) occurrence in tOff1.

This is what I' doing.

I'm planning on using one smaller list to gather the few objects that fit numerically from the much larger list of objects. Once the smaller selected objects are parsed into an array I can use those only for my needs

Example of MTML: "<message>" objects

<message>
At 15:46 22/08/2004 -0700, Mark Brownell wrote:

<important Phrase>So let's say that you have hundreds of points either in an array or comma delimited. What would be the <soWhat>fastest way to get the value of the item just less than 100 in this following example? </soWhat> </important Phrase>

<I need this sorted>1, 34, 67, 99, 109, 121, 133, 144, 155, (answer = item 4) -- 99 </I need this sorted>

Would I have to loop through each one checking each during a repeat for the last item less-than 100 or is there a faster way to get the value in item 4. <sort this>Every time I can drop a repeat loop seems to be a way to optimize the result based on speed issues. </sort this>

<won't work>If you have only have hundreds of points, then a loop may not be too bad. </won't work>
</message>


Now let's say that I had thousands of message objects in a single document and I wanted to use this to get the numerical points for each message objects start and end points.

put the offsets(myString, "<message>" into zap1
put the offsets(myString, "</message>" into zap2

now if I use this same function for:
put the offsets(myString, "<soWhat>" into soWhatList

Let's say that I get ten hits for "<soWhat>" and they occur at several numerical locations that turn out to be in message objects 20, 50, 60, 77, 200, etc...
What I do now is parse all 1000 message objects and check each one for the existence of the "<soWhat>" element.


What I would like to do is just go to the ten message objects numerical start and end points and parse them only. I do this by checking to see if a "<soWhat>" number falls between a message objects' start and end points. If that occurs then I would add that message to my smaller list of message objects.

So this: 40, 50, 60, 70 would be used on this:

5, 15, 25, 35, 45, 55, 65, 75, 85, 95, to select items 4,5,6, and 7

the first item 40 happens just after 35 in the larger list at the forth item
the second item 50 happens just after 45 in the larger list at the fifth item
the third item 60 happens just after 55 in the larger list at the sixth item
the forth item 70 happens just after 65 in the larger list at the seventh item


If I know the item number I'm interested in then I can use the value found at that item to get that object. This would be a much faster process than looping through every object to see if it has the secondary object of interest.

You might consider doing something like ....
    repeat for each line L of tOff1
        put L & comma & "<a>" after tAllOff
    end repeat
    repeat for each line L of tOff2
       put L & comma & "</a>" after tAllOff
   end repeat
   sort tAllOff by item 1
and then working on the combined offset list.

Don't need more repeat loops.

Hmmmm - so maybe it would be worth asking for a single function to take a list of strings and put their offsets into a single list :
put the offsets of "<a>,</a>" of myText into tAllOff
which would put
1, <a>
4, </a>
9, <a>
11, <a>
25, </a>
... etc.
into the list. i.e. somewhat like the earlier "split by string1 and string2" idea.


-- Alex.

That's how my first tests went five years ago. It's clunky working through a single list of doubles. By using a single list of singles you can do my example above, and in half the time possibly.


Mark

_______________________________________________
use-revolution mailing list
[EMAIL PROTECTED]
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to