[fpc-pascal] fgl unit bug in generic class TFPGMap
Flávio Etrusco
flavio.etrusco at gmail.com
Mon Oct 27 23:37:58 CET 2014
On Mon, Oct 27, 2014 at 3:45 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> Am 26.10.2014 05:51, schrieb Flávio Etrusco:
>
>> On Fri, Oct 3, 2014 at 12:42 PM, Dennis Poon <dennis at avidsoft.com.hk>
>> wrote:
>>>
>>> I think I found a bug in TFPGMap.
>>> Hope some of you can verify it.
>>>
>>> The bug seems to relate to the binary search used in the method "FIND"
>>> but
>>> it does not occur for all string key values or at all capacity of the
>>> map.
>>> Seems only occur at the second item added and when it is certain string
>>> values.
>>>
>>> I tried to debug it but cannot step into the codes of fgl unit so cannot
>>> find the cause.
>>>
>>> Please help.
>>>
>>> Dennis
>>>
>>> =====================
>>> unit Unit1;
>>
>> (...)
>>>
>>> TMapOfObjects=class(specialize TFPGMap < String, TObject> )
>>
>> (...)
>>
>> I don't see any calls to 'Sort' or 'Sorted' in your code. 'Find', as
>> you note, does a binary search thus expects the items to be sorted.
>> You can also use 'IndexOf' instead.
>
> But a map should not need any call to Sort, because it's the map's task to
> organize its data structure in such a way that Find does work as it should.
>
> Regards,
> Sven
That's my opinion too, I just replied based on the source code.
Actually I had written some comments WRT that in my reply but removed
it before sending because I don't know the history of the component. I
was going to say something like: it's very unfortunate that the "most
discoverable" map for FPC is a simple list of pairs and doesn't have
clear/standard map API, and instead exposes its guts.
Maybe Find should call IndexOf if Sorted = False for now?
Regards,
Flávio
More information about the fpc-pascal
mailing list