findany_from()
- Posted by Larry Miller <larrymiller at ?as?tel.net> Apr 22, 2008
- 554 views
I have been experimenting with this function found in SourceForge SVN. I have a smaller, simpler, and faster version:
global function findany_from(sequence needles, sequence haystack, integer start) for i = start to length(haystack) do if find(haystack[i],needles) then return i end if end for return 0 end function
Another option was mentioned in the TODO section. I wrote a version using find_from() to search the haystack.
global function findany_from2(sequence needles, sequence haystack, integer start) integer index,result if start > length(haystack) then return 0 end if result=1e9 for i=1 to length(needles) do index=find_from(needles[i],haystack,start) if index then if index<result then result=index end if end if end for if result<1e9 then return result else return 0 end if end function
There is no clear winner when comparing performance. Either can be much faster than the other, depending on the nature of the data. The first is a clear winner in terms of simplicity and clarity. Larry Miller