[fpc-pascal] IntList

Sven Barth pascaldragon at googlemail.com
Tue Oct 19 20:06:23 CEST 2010


Am 19.10.2010 19:54, schrieb Juha Manninen (gmail):
> On Tuesday 19 October 2010 19:10:39 Luiz Americo Pereira Camara wrote:
>> Yes it's ready in fpc 240:
>>
>> uses
>>    Fgl;
>>
>> type
>>    TIntegerList = specialize TFPGList<Integer>;
>
> Well, yes. It is almost as good as a dedicated class. It has a Sort method but
> you must feed the compare function for it.
> It does not have a Find method for a binary search in a sorted list.
> Indexof does a linear search.
>
> Anyway, it could be used as a base class in Lazarus. I don't know what is the
> Lazarus team's policy for using generics in Lazarus code-base.
>
> In FPC 2.4.0 I had problems with memory consumption of generics containers.
> A<Integer, Integer>  map hogged gigabytes of memory while my data took only
> kilobytes (less than 1 MB for sure), on a 64 bit Linux.
> Now I have the latest FPC trunk 2.5.1 and the problems are gone. I added
> 100000 integers to both a List and to a Map and didn't even notice the memory
> increase in resource monitor.
>
>    TIntegerList = specialize TFPGList<Integer>;
>    TIntegerMap = specialize TFPGMap<Integer, Integer>;
>
> TFPGMap's problem still is that it is not a hash map and is butt-slow with
> lots of data. A hash map is a superior container type, it really should be
> changed.
> Besides, people expect to get a hash map when they see "map" in the class
> name. Now they get a list which is deceivingly named as "map".

As you seem to have experience with efficient data structures, what 
about creating such a generic hash map? :)

(but don't use 2.4.2rc1 and current/unpatched 2.4.3 as a test base as 
those don't have the fixes from trunk to make "specialize" working again)

Regards,
Sven



More information about the fpc-pascal mailing list