[fpc-pascal] fgl unit bug in generic class TFPGMap

Sven Barth pascaldragon at googlemail.com
Mon Oct 27 19:45:25 CET 2014


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



More information about the fpc-pascal mailing list