Re: Looking for the best "Parse"...
- Posted by Igor Kachan <kinz at peterlink.ru> Oct 27, 2001
- 385 views
Ýòî ñîîáùåíèå â ôîðìàòå MIME ñîñòîèò èç íåñêîëüêèõ ÷àñòåé. ------=_NextPart_000_01C15F3C.6EFF8300 Hi Derek, Hi Jiri, I have prepared new variant of this parse play. I apply the "delete double" method to jparse2() function. This new iteration is in the attachment with my own bench. You can see my results below. These are times of 10000 iterations on my a 386 in plain Dos-32 mode jparse2() jparse3() -- new 21.59 21.48 21.59 21.48 21.64 21.47 21.59 21.47 21.59 21.47 21.58 21.48 21.58 21.53 21.59 21.53 21.59 21.47 ----------------------------------average 21.59 21.48 Note, I don't know algorithms well enough, both Cassidy's and any new, I just read about that fox, which jumps over lazy dog, to see if there is misprint in my new iterations to the best function or no there is not. I am not real author of any task and solution in this play, I just search for doubled things and try delete them with the help of Euphoria's inner power, so my name and these tasks and functions are not well compatible things, I think. And "delete double" method is an old one, same as ... I don't know as. If you'll see Colin's solution near the modifired Cassidy's function, you can see Colin just apply "double delete" method to that recursive solution. You can also to apply this "delete double" method to Cassidy's *test frase* and delete mistakes from that classic "delete double" test OK to finish this subject for the robast Eu Dos-32 programming ? I say, there is OK with humor here, no ? Regards, Igor Kachan kinz at peterlink.ru ------=_NextPart_000_01C15F3C.6EFF8300 Content-Type: application/octet-stream; name="Parse1.e" Content-Transfer-Encoding: 7bit Content-Description: Parse1.e (E ) Content-Disposition: attachment; filename="Parse1.e" include wildcard.e function jparse2(sequence s, sequence s1, sequence s2) -- replace every occurrence of s1 in s by s2 -- case insensitive search sequence os,u,v integer i,j,m os = {} u = lower(s) v = lower(s1) m = length(s1) i = match(v, u) j = 1 while i do os &= s[j..j+i-2] & s2 j += i+m-1 u = u[i+m..length(u)] i = match(v, u) end while return os & s[j..length(s)] end function integer k,i,j,m sequence os,u,v function jparse3(sequence s, sequence s1, sequence s2) -- replace every occurrence of s1 in s by s2 -- case insensitive search -- sequence os,u,v -- integer k,i,j,m os = {} u = lower(s) v = lower(s1) m = length(s1) j = 1 for t=1 to 111111111 do i = match(v, u) if not i then exit end if k = i+m os &= s[j..j+i-2] & s2 j += k-1 u = u[k..length(u)] end for return os & s[j..length(s)] end function sequence text text = jparse3 ("The $A jumped over the lazy dog.","$A","quick brown fox") puts (1, text & "\n") atom T T=time() for p=0 to 10000 do text = jparse2 ("The $A jumped over the lazy dog.","$A","quick brown fox") end for T=time()-T ? T T=time() for p=0 to 10000 do text = jparse3 ("The $A jumped over the lazy dog.","$A","quick brown fox") end for T=time()-T ?T ------=_NextPart_000_01C15F3C.6EFF8300--