RE: Sequence Slicing (Was RE: Tough ciphers?)
- Posted by Rod Jackson <rodjackson_x at hotmail.com> Mar 15, 2002
- 427 views
??? 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))