1. Re: Faster Please .. The End (not yet)

> global function sNestDelimited(sequence s, atom x)
> integer len, start, endx
> sequence dseq,dl
>    dseq={}
>    len = length(s)
>    start = 1
>    for i = 1 to len do
>        if s[i] = x then
>           endx = i-1
>           dseq &= {s[start..endx]}
>           start = i+1
>        end if
>    end for
> return dseq
> end function

1. This will only work properly when the last character of s is the 
delimiter x, and the
first character isn't. If not, the last substring won't be in dseq or 
there will be
an error (start = 1, endx = i-1 = 0, dseq &= {s[1..0]}). Also: if the 
delimiter x is
found twice without characters in between (like {1, 2, x, x, ...}), that 
same error
will occur.
2. Isn't 'seq1 &= {seq2}' the same as 'seq1 = append(seq1, seq2)' ? 
Robert, which one is
faster in this case? Isn't append optimized in this case (A=append(A,B)) ?
New version:

global function sNestDelimited(sequence s, atom x)
integer start, len
sequence dseq
dseq = {}
start = 1
len = length(s)
for i = 1 to len do
	if s[i] = x then
		if start = i then
			dseq = append(dseq, {})
		else
			dseq = append(dseq, s[start..i-1])
		end if
		start = i+1
	end if
end for
if start <= len then dseq = append(dseq, s[start..len]) end if
return dseq
end function
--

Tommy Carlier
tommy online: http://users.pandora.be/tommycarlier

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu