[fpc-devel] Re: enumerators

Marco van de Voort marcov at stack.nl
Mon Nov 15 17:24:08 CET 2010


In our previous episode, Hans-Peter Diettrich said:
> >> At least the example code has to be made work, i.e. the nonsense statement
> >>    DoSomething(ch(i));
> >> has to be changed into something like
> >>    DoSomething(GetUTF8char(s,i));
> >> before we can can talk honestly about the order of the loop.
> > 
> > The other of the algorithm is then still O(n^2), since UTF8Char will already
> > be O(n)?
> 
> The total order will be something between O(n^1) and O(n^2), depending 
> on many factors (what is "n"?...).

Doesn't matter, utf8 chars or encoding granularity.
 
> I also doubt that UTF8char is a reasonable type for the loop variable - 
> IMO UTF32char were a much better choice...

First you would have to come up with a workable model for s[x] being
utf32chars in general that doesn't suffer from O(N^2) performance
degradation (read/write) 

And for it to be useful, it must be workable for more than only the most
basic loops, but also for e.g.

if length(s)>1 then
  for i:=1 to length(s)-1 do
    s[i]:=s[i+1];

and similar loops that might read/write more than once, and use
calculated expressions as the parameter to []




More information about the fpc-devel mailing list