Re: Faster please....

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

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>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Two function for delimited data, one uses match( 
)&nbsp;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>&nbsp;</DIV>
<DIV>find isnt used here, sorry</DIV>
<DIV>Purpose: to return nested sequence using delimiter chars salted throughout 
a flat sequence.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Whoops</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Two function for delimited data, one uses match( 
)&nbsp;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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>global function sDelimited(sequence s, integer 
delimiter)<BR>-- returns: sequence containing indices of all 
matches<BR>--&nbsp;if unsuccessful return empty sequence {}<BR>&nbsp; object 
found <BR>&nbsp; sequence dl, dseq<BR>&nbsp; integer start, endx<BR>&nbsp; 
<BR>&nbsp; dl = repeat(dl, 1)<BR>&nbsp; found = match(dl, s)<BR>&nbsp; if found 
then<BR>&nbsp;&nbsp;&nbsp;&nbsp; found &amp;= found + 
sDelimited(s[found+1..length(s)], delimiter)<BR>&nbsp; 
else<BR>&nbsp;&nbsp;&nbsp;&nbsp; return {}<BR>&nbsp; end if<BR>&nbsp; dseq = 
{}<BR>&nbsp; start = 1<BR>&nbsp; for i = 1 to length(found) 
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endx = 
found[i]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dseq &amp;= 
{s[start...endx]}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start = endx + 1<BR>&nbsp; 
end for<BR>&nbsp; return dseq<BR>end function</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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>&nbsp;&nbsp; len = length(s)<BR>&nbsp;&nbsp; dl = repeat(delimiter, 
1)<BR>&nbsp;&nbsp; start = 1<BR>&nbsp;&nbsp; for i = 1 to len 
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if equal(s[i..i],dl) 
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; endx = i - 
1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dseq &amp;= 
{s[start..endx]}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start
= i + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp; end 
for<BR>&nbsp;&nbsp; return dseq<BR>end function</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards,</DIV>

------=_NextPart_000_0005_01C3D8A0.313045C0--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu