RE: Sequence Slicing (Was RE: Tough ciphers?)

new topic     » goto parent     » topic index » view thread      » older message » newer message

???

Am I reading this right? Are you saying that this routine
will actually find elements in a sequence faster than
taking a slice of the sequence and using find() to search
the slice?

Rod Jackson


bensler at mail.com wrote:
> This is fast and works on any slice of a sequence. Sanity checks could 
> be added.
> 
> function range_find(object x, sequence s, integer pos1, integer pos2)
>  atom found
>    found = 0
>    while not found and pos1 <= pos2 do
>       found = equal(x,s[pos1]) * pos1
>       pos1 +=1
>    end while
>    return found
> end function
> 
> This is the test that I used. I wasn't concerned with accuracy, because 
> the routine beats find() by a long shot.
> 
> <TEST>
<snip>
> <END TEST>
> 
> The control test used:
> found = find('\n',temp[f..length(temp)]
> 
> instead of:
> found = range_find('\n',temp,f,length(temp))

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu