[Lazarus] Foreach?
Flávio Etrusco
flavio.etrusco at gmail.com
Sun Jun 9 00:30:04 CEST 2013
On Sat, Jun 8, 2013 at 4:35 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> On 08.06.2013 19:52, Antônio wrote:
>>
>> That is not so bad, since what FindComponent loop does is the same as
>> Barth done with his loop, matching the name of the component.
>
>
> Thinking about it a bit more in the end both approaches should be O(n):
>
> In my approach you have the loop over all Controls and then the "loop" when
> doing the Pos. The latter can be seen as neglectable and by using Copy + "="
> this can be reduced to a constant time. So it's O(n).
>
> Your approach first has the constant loop from 1 to 10, then the
> FindComponent loop which is O(n) and the way of finding the correct
> component name which can be considered constant again.
>
> So only difference might be execution speed and that would need to be tested
> especially with a random distribution of the Button controls among the
> Controls array.
If you use AnsiStartWith (or similar) your (single loop) version will
be really O(n) (for the number of Controls). And the FindComponent
approach then be rightfully considered O(m^p) (no of buttons, no of
Components - not Controls).
There's no arguing FindComponent (or GetFieldAddress if the buttons
are published/streamed) is more readable, tough.
> Sidenote: I prefer being called by my first name on the mailing list.
>
> Regards,
> Sven
>
Best regards,
Flávio
More information about the Lazarus
mailing list