Re: Faster please....
- Posted by "Euman" <euman at bellsouth.net> Jan 12, 2004
- 412 views
This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C3D8A0.313045C0 charset="iso-8859-1" Hello again all, Two function for delimited data, one uses match( ) recursively and the other equal( ). (The first came from an idea by Brian Broker the second, Ron Austin) find isnt used here, sorry Purpose: to return nested sequence using delimiter chars salted throughout a flat sequence. Whoops ----- Original Message ----- From: Euman To: EuForum at topica.com Sent: Monday, January 12, 2004 12:02 AM Subject: Faster please.... Hello all, Two function for delimited data, one uses match( ) recursively and the other find( ). (The first came from an idea by Brian Broker the second, Ron Austin) Maybe someday, someone will test which one wins..? If there are faster ways, I would appreciate the hand up... global function sDelimited(sequence s, integer delimiter) -- returns: sequence containing indices of all matches -- if unsuccessful return empty sequence {} object found sequence dl, dseq integer start, endx dl = repeat(dl, 1) found = match(dl, s) if found then found &= found + sDelimited(s[found+1..length(s)], delimiter) else return {} end if dseq = {} start = 1 for i = 1 to length(found) do endx = found[i] dseq &= {s[start...endx]} start = endx + 1 end for return dseq end function global function sDelimited(sequence s, integer delimiter) integer len, start, endx sequence dseq len = length(s) dl = repeat(delimiter, 1) start = 1 for i = 1 to len do if equal(s[i..i],dl) then endx = i - 1 dseq &= {s[start..endx]} start = i + 1 end if end for return dseq end function Regards, Euman ------=_NextPart_000_0005_01C3D8A0.313045C0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 8bit <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1276" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2> <DIV><FONT face=Arial size=2>Hello again all,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Two function for delimited data, one uses match( ) recursively and the other equal( ).</FONT></DIV> <DIV><FONT face=Arial size=2>(The first came from an idea by Brian Broker the second, Ron Austin)</FONT></DIV> <DIV> </DIV> <DIV>find isnt used here, sorry</DIV> <DIV>Purpose: to return nested sequence using delimiter chars salted throughout a flat sequence.</DIV> <DIV> </DIV> <DIV>Whoops</DIV> <DIV> </DIV> <DIV> </DIV></FONT></DIV> <DIV style="FONT: 10pt arial">----- Original Message ----- <DIV style="BACKGROUND: #e4e4e4; font-color: black"><B>From:</B> <A title=euman at bellsouth.net href="mailto:euman at bellsouth.net">Euman</A> </DIV> <DIV><B>To:</B> <A title=EuForum at topica.com href="mailto:EuForum at topica.com">EuForum at topica.com</A> </DIV> <DIV><B>Sent:</B> Monday, January 12, 2004 12:02 AM</DIV> <DIV><B>Subject:</B> Faster please....</DIV></DIV> <DIV><BR></DIV> <DIV><FONT face=Arial size=2>Hello all,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Two function for delimited data, one uses match( ) recursively and the other find( ).</FONT></DIV> <DIV><FONT face=Arial size=2>(The first came from an idea by Brian Broker the second, Ron Austin)</FONT></DIV> <DIV><FONT face=Arial size=2><FONT size=3></FONT></FONT> </DIV> <DIV><FONT face=Arial size=2>Maybe someday, someone will test which one wins..?</FONT></DIV> <DIV><FONT face=Arial size=2>If there are faster ways, I would appreciate the hand up...</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>global function sDelimited(sequence s, integer delimiter)<BR>-- returns: sequence containing indices of all matches<BR>-- if unsuccessful return empty sequence {}<BR> object found <BR> sequence dl, dseq<BR> integer start, endx<BR> <BR> dl = repeat(dl, 1)<BR> found = match(dl, s)<BR> if found then<BR> found &= found + sDelimited(s[found+1..length(s)], delimiter)<BR> else<BR> return {}<BR> end if<BR> dseq = {}<BR> start = 1<BR> for i = 1 to length(found) do<BR> endx = found[i]<BR> dseq &= {s[start...endx]}<BR> start = endx + 1<BR> end for<BR> return dseq<BR>end function</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>global function sDelimited(sequence s, integer delimiter)<BR>integer len, start, endx</FONT></DIV> <DIV><FONT face=Arial size=2>sequence dseq</FONT></DIV><FONT face=Arial size=2> <DIV><BR> len = length(s)<BR> dl = repeat(delimiter, 1)<BR> start = 1<BR> for i = 1 to len do<BR> if equal(s[i..i],dl) then<BR> endx = i - 1<BR> dseq &= {s[start..endx]}<BR> start = i + 1<BR> end if<BR> end for<BR> return dseq<BR>end function</DIV> <DIV> </DIV> <DIV>Regards,</DIV> ------=_NextPart_000_0005_01C3D8A0.313045C0--