[fpc-devel] Re: enumerators

Marco van de Voort marcov at stack.nl
Sun Nov 14 23:25:50 CET 2010


In our previous episode, Hans-Peter Diettrich said:
> > the O(N^2) stems from the fact that it is hard to get the ith
> > character in a a UTF8String in O(1). Suppose it is o(N), then the loop
> > is O(n^2).
> 
> With regards to UTF-8 (or other MBCS) strings, what does Length(s) 

The base size of the encoding (1 for shortstring/ansistring, regardless of
encoding, 2 for unicodestring/widestring regardless of encoding is UCS2 or
UTF16). 

> return in these cases? IMO other functions have to be used for the 
> determination of the true character count (as opposed to the char=byte 
> count).

> 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)?



More information about the fpc-devel mailing list